Browse Source

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
pull/46230/head
Phillip Webb 6 months ago committed by Andy Wilkinson
parent
commit
77176c0c60
  1. 10
      spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/ConfigurationPropertiesBeanRegistrar.java

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

@ -85,7 +85,15 @@ final class ConfigurationPropertiesBeanRegistrar { @@ -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) {

Loading…
Cancel
Save