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-projects-issues opened this issue Jul 11, 2012 · 4 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: bug A general bug
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues 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:

5 votes, 6 watchers

@spring-projects-issues
Copy link
Collaborator Author

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-projects-issues
Copy link
Collaborator Author

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-projects-issues
Copy link
Collaborator Author

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-projects-issues
Copy link
Collaborator Author

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
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants