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

Injection of Provider fails for prototype-scoped beans [SPR-9630] #14264

Closed
spring-projects-issues opened this issue Jul 24, 2012 · 6 comments
Closed
Assignees
Labels
type: bug
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

@spring-projects-issues spring-projects-issues commented Jul 24, 2012

Kilian Matt opened SPR-9630 and commented

I tried to migrate an existing spring application from 3.0.5 to 3.1.2 and I've noticed a strange bug, that the injection of a provider works the first time but passes subsequent times.

It seems due the call of DependencyDescriptor.increaseNestingLevel() in the constructor of DependencyObjectFactory. Since the Descriptor is cached, the subsequent calls to BeanFactory.resolveDependency no longer return a Provider, but a reference to the bean.

I've attached a testcase, which reproduces the problem. The bug seems to be introduced in 3.1.1, according to my tests.


Affects: 3.1.1

Attachments:

Issue Links:

  • #13819 @Inject Provider or @Autowired ObjectFactory issue with session scoped bean ("duplicates")

Referenced from: commits 6574393, d782558

2 votes, 7 watchers

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Jul 24, 2012

Kilian Matt commented

Conflicting change was introduced in c55362c for #13669

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Jul 25, 2012

Kilian Matt commented

Pull-Request with Patch #110

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Oct 11, 2012

Benjamin Sawary commented

The solution only works on field-injection. if you're using method-injection, the issue still remains.

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Oct 11, 2012

Juergen Hoeller commented

Benjamin, are you referring to the solution as shipped in 3.2 M2? According to our unit tests, this seems to work fine for both fields and methods...

In any case, it would be good to double-check what fails for you there, since we're about to ship 3.1.3 any day now (with the same fix applied).

Juergen

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Oct 11, 2012

Benjamin Sawary commented

Hello Juergen,
I've tested the solution with 3.1.3.SNAPSHOT-BUILD and changed the included unit-test to:

public static class ObjectFactoryInjectionBean implements Serializable {

	//@Inject
	private Provider<TestBean> testBeanFactory;

	public TestBean getTestBean() {
		return this.testBeanFactory.get();
	}
            
            @Inject
            public void setProvider(Provider<TestBean> testBeanFactory)
            {
               this.testBeanFactory = testBeanFactory;

}

Benjamin

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Oct 11, 2012

Juergen Hoeller commented

Thanks, Benjamin. It seems I'm able to reproduce this for the regular bean provider case when using method injection; I've only checked the bean collection case for fields and methods before.

We'll make sure to have this fixed in time for the 3.1.3 release.

Juergen

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug
Projects
None yet
Development

No branches or pull requests

2 participants