You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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.
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.
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
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
The text was updated successfully, but these errors were encountered: