use of org.springframework.boot.context.properties.bind.handler.IgnoreTopLevelConverterNotFoundBindHandler 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);
}
});
}
Aggregations