You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
BeanMethodInterceptor doesn't forward user-provided arguments to getBean(name, args) [SPR-12443] #17048
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.
Activity
spring-projects-issues commentedon Nov 18, 2014
Juergen Hoeller commented
Good point! This is an easy enough enhancement and opens up quite a bit of potential for custom configuration class arrangements...
Juergen