BeanFactory accepts getBean arguments for non-prototype beans as well

Issue: SPR-12488
This commit is contained in:
Juergen Hoeller
2014-12-01 19:05:26 +01:00
parent c5c5473d44
commit fa0ef2d87e
4 changed files with 43 additions and 28 deletions

View File

@@ -38,6 +38,7 @@ import org.springframework.beans.factory.config.BeanDefinitionHolder;
import org.springframework.beans.factory.support.ChildBeanDefinition;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.componentscan.simple.SimpleComponent;
import org.springframework.core.env.StandardEnvironment;
import org.springframework.core.io.DescriptiveResource;
@@ -470,7 +471,13 @@ public class ConfigurationClassPostProcessorTests {
@Test
public void testPrototypeArgumentsThroughBeanMethodCall() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(BeanArgumentConfig.class);
ApplicationContext ctx = new AnnotationConfigApplicationContext(BeanArgumentConfigWithPrototype.class);
ctx.getBean(FooFactory.class).createFoo(new BarArgument());
}
@Test
public void testSingletonArgumentsThroughBeanMethodCall() {
ApplicationContext ctx = new AnnotationConfigApplicationContext(BeanArgumentConfigWithSingleton.class);
ctx.getBean(FooFactory.class).createFoo(new BarArgument());
}
@@ -932,7 +939,7 @@ public class ConfigurationClassPostProcessorTests {
}
@Configuration
static class BeanArgumentConfig {
static class BeanArgumentConfigWithPrototype {
@Bean
@Scope("prototype")
@@ -951,6 +958,25 @@ public class ConfigurationClassPostProcessorTests {
}
}
@Configuration
static class BeanArgumentConfigWithSingleton {
@Bean @Lazy
public DependingFoo foo(final BarArgument bar) {
return new DependingFoo(bar);
}
@Bean
public FooFactory fooFactory() {
return new FooFactory() {
@Override
public DependingFoo createFoo(final BarArgument bar) {
return foo(bar);
}
};
}
}
static class BarArgument {
}