Skip to content

Commit

Permalink
Merge branch '2.5.x' into 2.6.x
Browse files Browse the repository at this point in the history
Closes gh-30581
  • Loading branch information
wilkinsona committed Apr 7, 2022
2 parents fa77e1c + d9b0efb commit a2c08f9
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -143,8 +143,12 @@ public static Map<String, ConfigurationPropertiesBean> getAll(ApplicationContext
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;
}

Expand All @@ -158,7 +162,9 @@ private static Map<String, ConfigurationPropertiesBean> getAll(ConfigurableAppli
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) {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,15 @@ void getAllReturnsAll() {
}
}

@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(
Expand Down Expand Up @@ -546,4 +555,15 @@ public String[] selectImports(AnnotationMetadata importingClassMetadata) {

}

@Configuration(proxyBeanMethods = false)
@ConfigurationProperties
static class StaticBeanMethodConfiguration {

@Bean
static String stringBean() {
return "example";
}

}

}

0 comments on commit a2c08f9

Please sign in to comment.