Merge branch '2.7.x'

pull/30627/head
Andy Wilkinson 3 years ago
commit 41213a8c4e

@ -148,8 +148,12 @@ public final class ConfigurationPropertiesBean {
return getAll((ConfigurableApplicationContext) applicationContext);
}
Map<String, ConfigurationPropertiesBean> propertiesBeans = new LinkedHashMap<>();
applicationContext.getBeansWithAnnotation(ConfigurationProperties.class)
.forEach((beanName, bean) -> propertiesBeans.put(beanName, get(applicationContext, bean, beanName)));
applicationContext.getBeansWithAnnotation(ConfigurationProperties.class).forEach((beanName, bean) -> {
ConfigurationPropertiesBean propertiesBean = get(applicationContext, bean, beanName);
if (propertiesBean != null) {
propertiesBeans.put(beanName, propertiesBean);
}
});
return propertiesBeans;
}
@ -163,7 +167,9 @@ public final class ConfigurationPropertiesBean {
try {
Object bean = beanFactory.getBean(beanName);
ConfigurationPropertiesBean propertiesBean = get(applicationContext, bean, beanName);
propertiesBeans.put(beanName, propertiesBean);
if (propertiesBean != null) {
propertiesBeans.put(beanName, propertiesBean);
}
}
catch (Exception ex) {
}

@ -78,6 +78,15 @@ class ConfigurationPropertiesBeanTests {
}
}
@Test
void getAllDoesNotFindABeanDeclaredInAStaticBeanMethodOnAConfigurationAndConfigurationPropertiesAnnotatedClass() {
try (AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
StaticBeanMethodConfiguration.class)) {
Map<String, ConfigurationPropertiesBean> all = ConfigurationPropertiesBean.getAll(context);
assertThat(all).containsOnlyKeys("configurationPropertiesBeanTests.StaticBeanMethodConfiguration");
}
}
@Test
void getAllWhenHasBadBeanDoesNotFail() {
try (AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
@ -604,6 +613,18 @@ class ConfigurationPropertiesBeanTests {
class ParameterizedConstructorInner {
ParameterizedConstructorInner(Integer age) {
}
}
@Configuration(proxyBeanMethods = false)
@ConfigurationProperties
static class StaticBeanMethodConfiguration {
@Bean
static String stringBean() {
return "example";
}
}

Loading…
Cancel
Save