В качестве примера рассмотрим пользовательскую аннотацию DeprecatedField, основанную на свойство my.props.fail-on-deprecation будет либо:
- не запускать приложение (если аннотированное свойство не равно нулю, а мое .props.fail-on-deprecation==true)
- или создайте журнал предупреждений и продолжите запуск (если аннотированное свойство не равно NULL и my.props. fail-on-deprecation==false)
Код: Выделить всё
// DeprecatedField.java
@Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE})
@Retention(RUNTIME)
@Documented
@Constraint(validatedBy = DeprecatedFieldValidator.class)
public @interface DeprecatedField {
String message() default "the property is deprecated and should be removed";
Class[] groups() default {};
Class
Подробнее здесь: [url]https://stackoverflow.com/questions/78694466/how-to-suppress-and-log-custom-spring-boot-configuration-properties-constraint-v[/url]
Мобильная версия