Skip to content

Commit 0088922

Browse files
committed
checkConfigurationClassCandidate explicitly skips factory method definitions
Issue: SPR-14603 (cherry picked from commit 1fbd047)
1 parent 57fbdc0 commit 0088922

File tree

2 files changed

+31
-9
lines changed

2 files changed

+31
-9
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2015 the original author or authors.
2+
* Copyright 2002-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -79,7 +79,7 @@ abstract class ConfigurationClassUtils {
7979
*/
8080
public static boolean checkConfigurationClassCandidate(BeanDefinition beanDef, MetadataReaderFactory metadataReaderFactory) {
8181
String className = beanDef.getBeanClassName();
82-
if (className == null) {
82+
if (className == null || beanDef.getFactoryMethodName() != null) {
8383
return false;
8484
}
8585

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

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@
4343
import org.springframework.beans.factory.annotation.Qualifier;
4444
import org.springframework.beans.factory.annotation.QualifierAnnotationAutowireCandidateResolver;
4545
import org.springframework.beans.factory.config.BeanDefinitionHolder;
46+
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
47+
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
48+
import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor;
4649
import org.springframework.beans.factory.support.ChildBeanDefinition;
4750
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
4851
import org.springframework.beans.factory.support.RootBeanDefinition;
@@ -794,6 +797,12 @@ public void testNameClashBetweenConfigurationClassAndBean() {
794797
ctx.getBean("myTestBean", TestBean.class);
795798
}
796799

800+
@Test
801+
public void testBeanDefinitionRegistryPostProcessorConfig() {
802+
ApplicationContext ctx = new AnnotationConfigApplicationContext(BeanDefinitionRegistryPostProcessorConfig.class);
803+
assertTrue(ctx.getBean("myTestBean") instanceof TestBean);
804+
}
805+
797806

798807
// -------------------------------------------------------------------------
799808

@@ -860,17 +869,15 @@ public Bar(Foo foo) {
860869
@Configuration
861870
static class UnloadedConfig {
862871

863-
public @Bean
864-
Foo foo() {
872+
public @Bean Foo foo() {
865873
return new Foo();
866874
}
867875
}
868876

869877
@Configuration
870878
static class LoadedConfig {
871879

872-
public @Bean
873-
Bar bar() {
880+
public @Bean Bar bar() {
874881
return new Bar(new Foo());
875882
}
876883
}
@@ -884,9 +891,7 @@ public static class ScopedProxyConsumer {
884891
@Configuration
885892
public static class ScopedProxyConfigurationClass {
886893

887-
@Bean
888-
@Lazy
889-
@Scope(proxyMode = ScopedProxyMode.INTERFACES)
894+
@Bean @Lazy @Scope(proxyMode = ScopedProxyMode.INTERFACES)
890895
public ITestBean scopedClass() {
891896
return new TestBean();
892897
}
@@ -1475,4 +1480,21 @@ public TestBean thing() {
14751480
public abstract TestBean getTestBean();
14761481
}
14771482

1483+
@Configuration
1484+
static class BeanDefinitionRegistryPostProcessorConfig {
1485+
1486+
@Bean
1487+
public static BeanDefinitionRegistryPostProcessor bdrpp() {
1488+
return new BeanDefinitionRegistryPostProcessor() {
1489+
@Override
1490+
public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) {
1491+
registry.registerBeanDefinition("myTestBean", new RootBeanDefinition(TestBean.class));
1492+
}
1493+
@Override
1494+
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) {
1495+
}
1496+
};
1497+
}
1498+
}
1499+
14781500
}

0 commit comments

Comments
 (0)