Update Spring to catch SPR-11069
This commit is contained in:
@@ -21,7 +21,6 @@ import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.beans.factory.BeanFactoryUtils;
|
||||
@@ -154,8 +153,7 @@ class OnBeanCondition extends SpringBootCondition implements ConfigurationCondit
|
||||
@SuppressWarnings("unchecked")
|
||||
Class<? extends Annotation> typeClass = (Class<? extends Annotation>) ClassUtils
|
||||
.forName(type, classLoader);
|
||||
Map<String, Object> annotated = beanFactory.getBeansWithAnnotation(typeClass);
|
||||
result = annotated.keySet().toArray(new String[annotated.size()]);
|
||||
result = beanFactory.getBeanNamesForAnnotation(typeClass);
|
||||
if (considerHierarchy) {
|
||||
if (beanFactory.getParentBeanFactory() instanceof ConfigurableListableBeanFactory) {
|
||||
String[] parentResult = getBeanNamesForAnnotation(
|
||||
|
||||
@@ -17,10 +17,14 @@
|
||||
package org.springframework.boot.autoconfigure.condition;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.FactoryBean;
|
||||
import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.ImportResource;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
@@ -93,6 +97,18 @@ public class ConditionalOnMissingBeanTests {
|
||||
assertEquals("foo", this.context.getBean("foo"));
|
||||
}
|
||||
|
||||
// Rigorous test for SPR-11069
|
||||
@Test
|
||||
public void testAnnotationOnMissingBeanConditionWithEagerFactoryBean() {
|
||||
this.context.register(FooConfiguration.class, OnAnnotationConfiguration.class,
|
||||
ConfigurationWithFactoryBean.class,
|
||||
PropertyPlaceholderAutoConfiguration.class);
|
||||
this.context.refresh();
|
||||
assertFalse(this.context.containsBean("bar"));
|
||||
assertTrue(this.context.containsBean("example"));
|
||||
assertEquals("foo", this.context.getBean("foo"));
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@ConditionalOnMissingBean(name = "foo")
|
||||
protected static class OnBeanNameConfiguration {
|
||||
@@ -111,6 +127,11 @@ public class ConditionalOnMissingBeanTests {
|
||||
}
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@ImportResource("org/springframework/boot/autoconfigure/condition/factorybean.xml")
|
||||
protected static class ConfigurationWithFactoryBean {
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@EnableScheduling
|
||||
protected static class FooConfiguration {
|
||||
@@ -159,4 +180,27 @@ public class ConditionalOnMissingBeanTests {
|
||||
|
||||
public static class ExampleBean {
|
||||
}
|
||||
|
||||
public static class ExampleFactoryBean implements FactoryBean<ExampleBean> {
|
||||
|
||||
public ExampleFactoryBean(String value) {
|
||||
Assert.state(!value.contains("$"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExampleBean getObject() throws Exception {
|
||||
return new ExampleBean();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<?> getObjectType() {
|
||||
return ExampleBean.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSingleton() {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||
|
||||
<bean id="example"
|
||||
class="org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBeanTests.ExampleFactoryBean">
|
||||
<constructor-arg value="${value:bar}" />
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
Reference in New Issue
Block a user