Provide better configuration properties binding exception message

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

Issue: 46232
This commit is contained in:
Phillip Webb 2025-06-30 16:50:13 -07:00
parent dd08a1b3d1
commit c005196b23
1 changed files with 9 additions and 1 deletions

View File

@ -85,7 +85,15 @@ final class ConfigurationPropertiesBeanRegistrar {
MergedAnnotation<ConfigurationProperties> annotation) { MergedAnnotation<ConfigurationProperties> annotation) {
Assert.state(annotation.isPresent(), () -> "No " + ConfigurationProperties.class.getSimpleName() Assert.state(annotation.isPresent(), () -> "No " + ConfigurationProperties.class.getSimpleName()
+ " annotation found on '" + type.getName() + "'."); + " 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) { private BeanDefinitionHolder createBeanDefinition(String beanName, Class<?> type) {