Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
spring-projects-issues opened this issue Nov 15, 2014 · 1 comment
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Nov 15, 2014

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

@spring-projects-issues
Copy link
Collaborator Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants