|
|
@ -51,6 +51,7 @@ import org.springframework.core.annotation.MergedAnnotations;
|
|
|
|
import org.springframework.core.convert.ConversionService;
|
|
|
|
import org.springframework.core.convert.ConversionService;
|
|
|
|
import org.springframework.core.env.PropertySources;
|
|
|
|
import org.springframework.core.env.PropertySources;
|
|
|
|
import org.springframework.util.Assert;
|
|
|
|
import org.springframework.util.Assert;
|
|
|
|
|
|
|
|
import org.springframework.validation.Errors;
|
|
|
|
import org.springframework.validation.Validator;
|
|
|
|
import org.springframework.validation.Validator;
|
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
|
|
|
|
|
|
|
|
@ -134,6 +135,7 @@ class ConfigurationPropertiesBinder {
|
|
|
|
: new IgnoreTopLevelConverterNotFoundBindHandler();
|
|
|
|
: new IgnoreTopLevelConverterNotFoundBindHandler();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
private List<Validator> getValidators(Bindable<?> target) {
|
|
|
|
private List<Validator> getValidators(Bindable<?> target) {
|
|
|
|
List<Validator> validators = new ArrayList<>(3);
|
|
|
|
List<Validator> validators = new ArrayList<>(3);
|
|
|
|
if (this.configurationPropertiesValidator != null) {
|
|
|
|
if (this.configurationPropertiesValidator != null) {
|
|
|
@ -142,9 +144,14 @@ class ConfigurationPropertiesBinder {
|
|
|
|
if (this.jsr303Present && target.getAnnotation(Validated.class) != null) {
|
|
|
|
if (this.jsr303Present && target.getAnnotation(Validated.class) != null) {
|
|
|
|
validators.add(getJsr303Validator());
|
|
|
|
validators.add(getJsr303Validator());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (target.getValue() != null && target.getValue().get() instanceof Validator validator) {
|
|
|
|
if (target.getValue() != null) {
|
|
|
|
|
|
|
|
if (target.getValue().get() instanceof Validator validator) {
|
|
|
|
validators.add(validator);
|
|
|
|
validators.add(validator);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (Validator.class.isAssignableFrom(target.getType().resolve())) {
|
|
|
|
|
|
|
|
validators.add(new SelfValidatingConstructorBoundBindableValidator((Bindable<? extends Validator>) target));
|
|
|
|
|
|
|
|
}
|
|
|
|
return validators;
|
|
|
|
return validators;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -250,4 +257,28 @@ class ConfigurationPropertiesBinder {
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* A {@code Validator} for a constructor-bound {@code Bindable} where the type being
|
|
|
|
|
|
|
|
* bound is itself a {@code Validator} implementation.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
static class SelfValidatingConstructorBoundBindableValidator implements Validator {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final Bindable<? extends Validator> bindable;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SelfValidatingConstructorBoundBindableValidator(Bindable<? extends Validator> bindable) {
|
|
|
|
|
|
|
|
this.bindable = bindable;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public boolean supports(Class<?> clazz) {
|
|
|
|
|
|
|
|
return clazz.isAssignableFrom(this.bindable.getType().resolve());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void validate(Object target, Errors errors) {
|
|
|
|
|
|
|
|
((Validator) target).validate(target, errors);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|