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

Injecting prototypes into tests using @Resource appears to be broken [SPR-9580] #14214

Closed
spring-issuemaster opened this issue Jul 11, 2012 · 4 comments
Assignees
Milestone

Comments

@spring-issuemaster
Copy link
Collaborator

@spring-issuemaster spring-issuemaster commented Jul 11, 2012

Tom Ziemer opened SPR-9580 and commented

When injecting a prototype bean into a test derived from AbstractJUnit4SpringContextTests using @Resource, it seems that the bean is only created once.
Prior to Spring 3.1.2 this was not the case, the framework provided a new instance for each test run.

As a workaround, I now use @Autowired + @Qualifier.

The attached project uses a unit test to show the problem. Changing the Spring version to 3.1.1-RELEASE (or lower) in the pom fixes the issue.


Affects: 3.1.2

Attachments:

Issue Links:

  • #14261 Regression: scoped beans being cached too aggressively

5 votes, 6 watchers

@spring-issuemaster
Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Jul 16, 2012

Juan Osuna commented

I am getting the same issue with previously working non-test-related production code. Upgrade from 3.1.1 to 3.1.2 seems to be causing several problems with session and prototype scopes.

I have an bean object tree with the root being session scope. The rest of the tree consists of prototype beans. The same prototype instance is being injected into different beans in the object tree rather than a new one being created for each @Resource field reference. This behavior should be logically impossible by definition.
Also, I am seeing cases where different session bean instances are being injected into prototype beans, where the session beans should be the same instance. It is almost like the expected behavior of prototype and session scopes has been swapped.

@spring-issuemaster
Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Jul 17, 2012

Michał Rembiszewski commented

Having a very similar behavior:

I have a session scoped bean A injected into another session scoped bean B with @Resource(name = "beanA"). When I login for the first time, everything works as expected. When I create subsequent sessions, I get a new instance of bean B for each session but they all have the same first instance of bean A injected. It looks as if this dependency was somehow cached in InjectionMetadata for BeanDefinition for bean B. I didn't investigate much farther since we are just trying migration from 3.0 to 3.1 and this was the first thing to come up.

@spring-issuemaster
Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Jul 21, 2012

Serg commented

I have the similar behavior with injectiong prototype into prototype using @Resource even in main application, not to mention tests. So I think it is major problem in spring 3.1.2

@spring-issuemaster
Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Jul 25, 2012

Dan Tran commented

Took us a few days to debug this issue after trying to upgrade from 3.1.1 to 3.1.2 for our jsf app

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.