Fix AutoConfigurationReport parent location

BeanFactory.getBean() already looks in the parent context
so we have to be careful and not use the parent when locating
the report singleton

Fixes gh-290
This commit is contained in:
Dave Syer 2014-01-30 10:20:34 +00:00
parent 3e9457ea8e
commit a21397dbe2
2 changed files with 17 additions and 3 deletions

View File

@ -25,7 +25,6 @@ import java.util.SortedMap;
import java.util.TreeMap;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.boot.autoconfigure.condition.ConditionOutcome;
import org.springframework.context.annotation.Condition;
@ -94,10 +93,10 @@ public class AutoConfigurationReport {
public static AutoConfigurationReport get(ConfigurableListableBeanFactory beanFactory) {
synchronized (beanFactory) {
AutoConfigurationReport report;
try {
if (beanFactory.containsSingleton(BEAN_NAME)) {
report = beanFactory.getBean(BEAN_NAME, AutoConfigurationReport.class);
}
catch (NoSuchBeanDefinitionException ex) {
else {
report = new AutoConfigurationReport();
beanFactory.registerSingleton(BEAN_NAME, report);
}

View File

@ -106,6 +106,21 @@ public class AutoConfigurationReportTests {
.getParentBeanFactory())));
}
@Test
public void parentBottomUp() throws Exception {
this.beanFactory = new DefaultListableBeanFactory(); // NB: overrides setup
this.beanFactory.setParentBeanFactory(new DefaultListableBeanFactory());
AutoConfigurationReport.get((ConfigurableListableBeanFactory) this.beanFactory
.getParentBeanFactory());
this.report = AutoConfigurationReport.get(this.beanFactory); // NB: overrides
// setup
assertThat(this.report, not(nullValue()));
assertThat(this.report, not(sameInstance(this.report.getParent())));
assertThat(this.report.getParent(), not(nullValue()));
assertThat(this.report.getParent().getParent(), nullValue());
}
@Test
public void recordConditionEvaluations() throws Exception {
this.outcome1 = new ConditionOutcome(false, "m1");