Skip to content

BeanMethodInterceptor doesn't forward user-provided arguments to getBean(name, args) [SPR-12443] #17048

Closed
@spring-projects-issues

Description

@spring-projects-issues

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:

Referenced from: commits 4bd75e4

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions