Skip to content

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

Closed

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

Activity

  1. spring-projects-issues commented on Nov 18, 2014

    @spring-projects-issues
    CollaboratorAuthor

    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

  2. added
    type: enhancement
    in: core
    on Jan 11, 2019
  3. added this to the 4.1.3 milestone on Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

in: coretype: enhancement

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions