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
pull/300/head
Dave Syer 11 years ago
parent 3e9457ea8e
commit a21397dbe2

@ -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);
}

@ -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");

Loading…
Cancel
Save