BeanFactory accepts getBean arguments for non-prototype beans as well
Issue: SPR-12488
This commit is contained in:
@@ -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 {
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user