Provide better configuration properties binding exception message

Update `ConfigurationPropertiesBeanRegistrar` to provide the name
of the bean and the type when failures occur.

Closes gh-46232
This commit is contained in:
Phillip Webb 2025-06-30 16:50:13 -07:00 committed by Andy Wilkinson
parent 73db54c82b
commit 77176c0c60
1 changed files with 9 additions and 1 deletions

View File

@ -85,7 +85,15 @@ final class ConfigurationPropertiesBeanRegistrar {
MergedAnnotation<ConfigurationProperties> annotation) {
Assert.state(annotation.isPresent(), () -> "No " + ConfigurationProperties.class.getSimpleName()
+ " annotation found on '" + type.getName() + "'.");
BeanDefinitionReaderUtils.registerBeanDefinition(createBeanDefinition(beanName, type), this.registry);
try {
BeanDefinitionHolder beanDefinition = createBeanDefinition(beanName, type);
BeanDefinitionReaderUtils.registerBeanDefinition(beanDefinition, this.registry);
}
catch (Throwable ex) {
throw new IllegalStateException(
"Unable to create configuration properties bean definition '%s' (%s)".formatted(beanName, type),
ex);
}
}
private BeanDefinitionHolder createBeanDefinition(String beanName, Class<?> type) {