Browse Source

checkConfigurationClassCandidate explicitly skips factory method definitions

Issue: SPR-14603
pull/1489/head
Juergen Hoeller 7 years ago
parent
commit
1fbd047003
  1. 2
      spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassUtils.java
  2. 36
      spring-context/src/test/java/org/springframework/context/annotation/ConfigurationClassPostProcessorTests.java

2
spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassUtils.java

@ -79,7 +79,7 @@ abstract class ConfigurationClassUtils { @@ -79,7 +79,7 @@ abstract class ConfigurationClassUtils {
*/
public static boolean checkConfigurationClassCandidate(BeanDefinition beanDef, MetadataReaderFactory metadataReaderFactory) {
String className = beanDef.getBeanClassName();
if (className == null) {
if (className == null || beanDef.getFactoryMethodName() != null) {
return false;
}

36
spring-context/src/test/java/org/springframework/context/annotation/ConfigurationClassPostProcessorTests.java

@ -43,6 +43,9 @@ import org.springframework.beans.factory.annotation.Lookup; @@ -43,6 +43,9 @@ import org.springframework.beans.factory.annotation.Lookup;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.QualifierAnnotationAutowireCandidateResolver;
import org.springframework.beans.factory.config.BeanDefinitionHolder;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor;
import org.springframework.beans.factory.support.ChildBeanDefinition;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.support.RootBeanDefinition;
@ -806,6 +809,12 @@ public class ConfigurationClassPostProcessorTests { @@ -806,6 +809,12 @@ public class ConfigurationClassPostProcessorTests {
ctx.getBean("myTestBean", TestBean.class);
}
@Test
public void testBeanDefinitionRegistryPostProcessorConfig() {
ApplicationContext ctx = new AnnotationConfigApplicationContext(BeanDefinitionRegistryPostProcessorConfig.class);
assertTrue(ctx.getBean("myTestBean") instanceof TestBean);
}
// -------------------------------------------------------------------------
@ -902,8 +911,7 @@ public class ConfigurationClassPostProcessorTests { @@ -902,8 +911,7 @@ public class ConfigurationClassPostProcessorTests {
@Configuration
static class UnloadedConfig {
public @Bean
Foo foo() {
public @Bean Foo foo() {
return new Foo();
}
}
@ -911,8 +919,7 @@ public class ConfigurationClassPostProcessorTests { @@ -911,8 +919,7 @@ public class ConfigurationClassPostProcessorTests {
@Configuration
static class LoadedConfig {
public @Bean
Bar bar() {
public @Bean Bar bar() {
return new Bar(new Foo());
}
}
@ -926,9 +933,7 @@ public class ConfigurationClassPostProcessorTests { @@ -926,9 +933,7 @@ public class ConfigurationClassPostProcessorTests {
@Configuration
public static class ScopedProxyConfigurationClass {
@Bean
@Lazy
@Scope(proxyMode = ScopedProxyMode.INTERFACES)
@Bean @Lazy @Scope(proxyMode = ScopedProxyMode.INTERFACES)
public ITestBean scopedClass() {
return new TestBean();
}
@ -1517,4 +1522,21 @@ public class ConfigurationClassPostProcessorTests { @@ -1517,4 +1522,21 @@ public class ConfigurationClassPostProcessorTests {
public abstract TestBean getTestBean();
}
@Configuration
static class BeanDefinitionRegistryPostProcessorConfig {
@Bean
public static BeanDefinitionRegistryPostProcessor bdrpp() {
return new BeanDefinitionRegistryPostProcessor() {
@Override
public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) {
registry.registerBeanDefinition("myTestBean", new RootBeanDefinition(TestBean.class));
}
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) {
}
};
}
}
}

Loading…
Cancel
Save