Closed
Description
Jorge Mozzino opened SPR-12443 and commented
Calling a prototype bean factory method with parameters ignores the parameters because they aren't passed to the getBean() call. If beans of the specified parameters' type exist then Spring will inject them into the prototype Bean. However, if they don't then a BeanCreationException will be thrown.
The following test reproduces the issue.
public class ConfigurationClassWithPrototypeFactoryWithArgumentsTest {
@Test
public void test() {
ApplicationContext ctx = new AnnotationConfigApplicationContext(Config.class);
ctx.getBean(FooFactory.class).createFoo(new Bar());
}
@Configuration
static class Config {
@Bean
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public Foo foo(final Bar bar) {
return new Foo(bar);
}
@Bean
public FooFactory fooFactory() {
return new FooFactory() {
@Override
public Foo createFoo(final Bar bar) {
return foo(bar);
}
};
}
}
static class Bar {}
static class Foo {
Foo(Bar bar) {}
}
static abstract class FooFactory {
abstract Foo createFoo(Bar bar);
}
}
I have this issue fixed and can submit a pull request.
Affects: 4.1.2
Issue Links:
- SPR-12443 breaks Spring Security's AuthenticationConfiguration [SPR-12488] #17094 SPR-12443 breaks Spring Security's AuthenticationConfiguration
- Regression: SPR-12443 breaks singleton bean references within a configuration class with null arguments [SPR-13887] #18460 Regression: SPR-12443 breaks singleton bean references within a configuration class with null arguments
Referenced from: commits 4bd75e4