Skip to content

Commit 77176c0

Browse files
philwebbwilkinsona
authored andcommitted
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
1 parent 73db54c commit 77176c0

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/ConfigurationPropertiesBeanRegistrar.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,15 @@ private void registerBeanDefinition(String beanName, Class<?> type,
8585
MergedAnnotation<ConfigurationProperties> annotation) {
8686
Assert.state(annotation.isPresent(), () -> "No " + ConfigurationProperties.class.getSimpleName()
8787
+ " annotation found on '" + type.getName() + "'.");
88-
BeanDefinitionReaderUtils.registerBeanDefinition(createBeanDefinition(beanName, type), this.registry);
88+
try {
89+
BeanDefinitionHolder beanDefinition = createBeanDefinition(beanName, type);
90+
BeanDefinitionReaderUtils.registerBeanDefinition(beanDefinition, this.registry);
91+
}
92+
catch (Throwable ex) {
93+
throw new IllegalStateException(
94+
"Unable to create configuration properties bean definition '%s' (%s)".formatted(beanName, type),
95+
ex);
96+
}
8997
}
9098

9199
private BeanDefinitionHolder createBeanDefinition(String beanName, Class<?> type) {

0 commit comments

Comments
 (0)