Configuration classes can opt into lite mode (proxyBeanMethods=false)

Closes gh-22461
This commit is contained in:
Juergen Hoeller
2019-03-08 15:59:11 +01:00
parent f5248ff13f
commit 1a8b3fba94
3 changed files with 61 additions and 39 deletions

View File

@@ -90,8 +90,7 @@ public class ConfigurationClassPostProcessorTests {
* <p>Technically, {@link ConfigurationClassPostProcessor} could fail to enhance the
* registered Configuration classes and many use cases would still work.
* Certain cases, however, like inter-bean singleton references would not.
* We test for such a case below, and in doing so prove that enhancement is
* working.
* We test for such a case below, and in doing so prove that enhancement is working.
*/
@Test
public void enhancementIsPresentBecauseSingletonSemanticsAreRespected() {
@@ -104,6 +103,16 @@ public class ConfigurationClassPostProcessorTests {
assertTrue(Arrays.asList(beanFactory.getDependentBeans("foo")).contains("bar"));
}
@Test
public void enhancementIsNotPresentForProxyBeanMethodsFlagSetToFalse() {
beanFactory.registerBeanDefinition("config", new RootBeanDefinition(NonEnhancedSingletonBeanConfig.class));
ConfigurationClassPostProcessor pp = new ConfigurationClassPostProcessor();
pp.postProcessBeanFactory(beanFactory);
Foo foo = beanFactory.getBean("foo", Foo.class);
Bar bar = beanFactory.getBean("bar", Bar.class);
assertNotSame(foo, bar.foo);
}
@Test
public void configurationIntrospectionOfInnerClassesWorksWithDotNameSyntax() {
beanFactory.registerBeanDefinition("config", new RootBeanDefinition(getClass().getName() + ".SingletonBeanConfig"));
@@ -115,8 +124,8 @@ public class ConfigurationClassPostProcessorTests {
}
/**
* Tests the fix for SPR-5655, a special workaround that prefers reflection
* over ASM if a bean class is already loaded.
* Tests the fix for SPR-5655, a special workaround that prefers reflection over ASM
* if a bean class is already loaded.
*/
@Test
public void alreadyLoadedConfigurationClasses() {
@@ -129,8 +138,7 @@ public class ConfigurationClassPostProcessorTests {
}
/**
* Tests whether a bean definition without a specified bean class is handled
* correctly.
* Tests whether a bean definition without a specified bean class is handled correctly.
*/
@Test
public void postProcessorIntrospectsInheritedDefinitionsCorrectly() {
@@ -1070,6 +1078,18 @@ public class ConfigurationClassPostProcessorTests {
}
}
@Configuration(proxyBeanMethods = false)
static class NonEnhancedSingletonBeanConfig {
public @Bean Foo foo() {
return new Foo();
}
public @Bean Bar bar() {
return new Bar(foo());
}
}
@Configuration
@Order(2)
static class OverridingSingletonBeanConfig {