use of org.springframework.boot.context.properties.source.UnboundElementsSourceFilter in project spring-boot by spring-projects.
the class ConfigurationPropertiesBinder method getBindHandler.
private <T> BindHandler getBindHandler(Bindable<T> target, ConfigurationProperties annotation) {
List<Validator> validators = getValidators(target);
BindHandler handler = getHandler();
handler = new ConfigurationPropertiesBindHandler(handler);
if (annotation.ignoreInvalidFields()) {
handler = new IgnoreErrorsBindHandler(handler);
}
if (!annotation.ignoreUnknownFields()) {
UnboundElementsSourceFilter filter = new UnboundElementsSourceFilter();
handler = new NoUnboundElementsBindHandler(handler, filter);
}
if (!validators.isEmpty()) {
handler = new ValidationBindHandler(handler, validators.toArray(new Validator[0]));
}
for (ConfigurationPropertiesBindHandlerAdvisor advisor : getBindHandlerAdvisors()) {
handler = advisor.apply(handler);
}
return handler;
}
use of org.springframework.boot.context.properties.source.UnboundElementsSourceFilter in project dubbo by alibaba.
the class BinderDubboConfigBinder method getBindHandler.
private BindHandler getBindHandler(boolean ignoreUnknownFields, boolean ignoreInvalidFields) {
BindHandler handler = BindHandler.DEFAULT;
if (ignoreInvalidFields) {
handler = new IgnoreErrorsBindHandler(handler);
}
if (!ignoreUnknownFields) {
UnboundElementsSourceFilter filter = new UnboundElementsSourceFilter();
handler = new NoUnboundElementsBindHandler(handler, filter);
}
return handler;
}
use of org.springframework.boot.context.properties.source.UnboundElementsSourceFilter in project cas by apereo.
the class CasConfigurationPropertiesValidator method validateConfiguration.
private void validateConfiguration(final Class clazz, final List<String> validationResults) {
val beans = BeanFactoryUtils.beansOfTypeIncludingAncestors(applicationContext.getBeanFactory(), clazz);
beans.values().forEach(bean -> {
val configBean = ConfigurationPropertiesBean.get(this.applicationContext, bean, UUID.randomUUID().toString());
val target = configBean.asBindTarget();
val annotation = configBean.getAnnotation();
val handler = new NoUnboundElementsBindHandler(new IgnoreTopLevelConverterNotFoundBindHandler(), new UnboundElementsSourceFilter());
val configBinder = new Binder(ConfigurationPropertySources.from(applicationContext.getEnvironment().getPropertySources()), new PropertySourcesPlaceholdersResolver(applicationContext.getEnvironment().getPropertySources()), applicationContext.getEnvironment().getConversionService(), null, null, null);
try {
configBinder.bind(annotation.prefix(), target, handler);
} catch (final BindException e) {
var message = "\n".concat(e.getMessage()).concat("\n");
if (e.getCause() != null) {
val cause = (UnboundConfigurationPropertiesException) e.getCause();
if (cause != null) {
message += cause.getUnboundProperties().stream().map(property -> String.format("%n\t%s = %s (Origin: %s)", property.getName(), property.getValue(), property.getOrigin())).collect(Collectors.joining("\n"));
}
}
validationResults.add(message);
}
});
}
use of org.springframework.boot.context.properties.source.UnboundElementsSourceFilter in project incubator-dubbo-spring-boot-project by apache.
the class BinderDubboConfigBinder method getBindHandler.
private BindHandler getBindHandler(boolean ignoreUnknownFields, boolean ignoreInvalidFields) {
BindHandler handler = BindHandler.DEFAULT;
if (ignoreInvalidFields) {
handler = new IgnoreErrorsBindHandler(handler);
}
if (!ignoreUnknownFields) {
UnboundElementsSourceFilter filter = new UnboundElementsSourceFilter();
handler = new NoUnboundElementsBindHandler(handler, filter);
}
return handler;
}
Aggregations