|
|
|
|
@ -298,8 +298,45 @@ public class ConfigurationClassPostProcessorTests {
@@ -298,8 +298,45 @@ public class ConfigurationClassPostProcessorTests {
|
|
|
|
|
beanFactory.registerBeanDefinition("config2", new RootBeanDefinition(SingletonBeanConfig.class)); |
|
|
|
|
ConfigurationClassPostProcessor pp = new ConfigurationClassPostProcessor(); |
|
|
|
|
pp.postProcessBeanFactory(beanFactory); |
|
|
|
|
assertTrue(beanFactory.getBean(Foo.class) instanceof ExtendedFoo); |
|
|
|
|
beanFactory.getBean(Bar.class); |
|
|
|
|
|
|
|
|
|
Foo foo = beanFactory.getBean(Foo.class); |
|
|
|
|
assertTrue(foo instanceof ExtendedFoo); |
|
|
|
|
Bar bar = beanFactory.getBean(Bar.class); |
|
|
|
|
assertSame(foo, bar.foo); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void configurationClassesWithValidOverridingForProgrammaticCall() { |
|
|
|
|
beanFactory.registerBeanDefinition("config1", new RootBeanDefinition(OverridingAgainSingletonBeanConfig.class)); |
|
|
|
|
beanFactory.registerBeanDefinition("config2", new RootBeanDefinition(OverridingSingletonBeanConfig.class)); |
|
|
|
|
beanFactory.registerBeanDefinition("config3", new RootBeanDefinition(SingletonBeanConfig.class)); |
|
|
|
|
ConfigurationClassPostProcessor pp = new ConfigurationClassPostProcessor(); |
|
|
|
|
pp.postProcessBeanFactory(beanFactory); |
|
|
|
|
|
|
|
|
|
Foo foo = beanFactory.getBean(Foo.class); |
|
|
|
|
assertTrue(foo instanceof ExtendedAgainFoo); |
|
|
|
|
Bar bar = beanFactory.getBean(Bar.class); |
|
|
|
|
assertSame(foo, bar.foo); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void configurationClassesWithInvalidOverridingForProgrammaticCall() { |
|
|
|
|
beanFactory.registerBeanDefinition("config1", new RootBeanDefinition(InvalidOverridingSingletonBeanConfig.class)); |
|
|
|
|
beanFactory.registerBeanDefinition("config2", new RootBeanDefinition(OverridingSingletonBeanConfig.class)); |
|
|
|
|
beanFactory.registerBeanDefinition("config3", new RootBeanDefinition(SingletonBeanConfig.class)); |
|
|
|
|
ConfigurationClassPostProcessor pp = new ConfigurationClassPostProcessor(); |
|
|
|
|
pp.postProcessBeanFactory(beanFactory); |
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
beanFactory.getBean(Bar.class); |
|
|
|
|
fail("Should have thrown BeanCreationException"); |
|
|
|
|
} |
|
|
|
|
catch (BeanCreationException ex) { |
|
|
|
|
assertTrue(ex.getMessage().contains("OverridingSingletonBeanConfig.foo")); |
|
|
|
|
assertTrue(ex.getMessage().contains(ExtendedFoo.class.getName())); |
|
|
|
|
assertTrue(ex.getMessage().contains(Foo.class.getName())); |
|
|
|
|
assertTrue(ex.getMessage().contains("InvalidOverridingSingletonBeanConfig")); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
@ -311,6 +348,7 @@ public class ConfigurationClassPostProcessorTests {
@@ -311,6 +348,7 @@ public class ConfigurationClassPostProcessorTests {
|
|
|
|
|
beanFactory.registerBeanDefinition("consumer", new RootBeanDefinition(ScopedProxyConsumer.class)); |
|
|
|
|
ConfigurationClassPostProcessor pp = new ConfigurationClassPostProcessor(); |
|
|
|
|
pp.postProcessBeanFactory(beanFactory); |
|
|
|
|
|
|
|
|
|
ITestBean injected = beanFactory.getBean("consumer", ScopedProxyConsumer.class).testBean; |
|
|
|
|
assertTrue(injected instanceof ScopedObject); |
|
|
|
|
assertSame(beanFactory.getBean("scopedClass"), injected); |
|
|
|
|
@ -549,13 +587,11 @@ public class ConfigurationClassPostProcessorTests {
@@ -549,13 +587,11 @@ public class ConfigurationClassPostProcessorTests {
|
|
|
|
|
@Order(1) |
|
|
|
|
static class SingletonBeanConfig { |
|
|
|
|
|
|
|
|
|
public @Bean |
|
|
|
|
Foo foo() { |
|
|
|
|
public @Bean Foo foo() { |
|
|
|
|
return new Foo(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public @Bean |
|
|
|
|
Bar bar() { |
|
|
|
|
public @Bean Bar bar() { |
|
|
|
|
return new Bar(foo()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
@ -564,23 +600,40 @@ public class ConfigurationClassPostProcessorTests {
@@ -564,23 +600,40 @@ public class ConfigurationClassPostProcessorTests {
|
|
|
|
|
@Order(2) |
|
|
|
|
static class OverridingSingletonBeanConfig { |
|
|
|
|
|
|
|
|
|
public @Bean |
|
|
|
|
ExtendedFoo foo() { |
|
|
|
|
public @Bean ExtendedFoo foo() { |
|
|
|
|
return new ExtendedFoo(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public @Bean |
|
|
|
|
Bar bar() { |
|
|
|
|
public @Bean Bar bar() { |
|
|
|
|
return new Bar(foo()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Configuration |
|
|
|
|
static class OverridingAgainSingletonBeanConfig { |
|
|
|
|
|
|
|
|
|
public @Bean ExtendedAgainFoo foo() { |
|
|
|
|
return new ExtendedAgainFoo(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Configuration |
|
|
|
|
static class InvalidOverridingSingletonBeanConfig { |
|
|
|
|
|
|
|
|
|
public @Bean Foo foo() { |
|
|
|
|
return new Foo(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static class Foo { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static class ExtendedFoo extends Foo { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static class ExtendedAgainFoo extends ExtendedFoo { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static class Bar { |
|
|
|
|
|
|
|
|
|
final Foo foo; |
|
|
|
|
|