Prototype with changing bean class does not get populated with dependencies after type switch [SPR-12526] #17131
Labels
in: core
Issues in core modules (aop, beans, core, context, expression)
status: backported
An issue that has been backported to maintenance branches
type: bug
A general bug
Milestone
Marcin Piela opened SPR-12526 and commented
I created an interface (Service) with two implementations (FirstService, SecondService) with one dependency each (DependencyOne, DependencyTwo, respectively). The dependencies are to be injected via a
@Resource
annotated setter method.In a spring java configuration class I created a
@Bean
method with@Scope
=prototype that based on some custom condition creates FirstService or SecondService using "new" operator. The method return type is Service.The problem is that when the method first creates an instance of FirstService and then the custom condition changes and on the second run an instance of SecondService is created it (SecondService instance) does not get populated with dependencies.
I've attached a simple maven module with a test case to demonstrate the issue.
Affects: 3.2.12, 4.0.8, 4.1.2
Attachments:
Referenced from: commits e118086, 568e963, 809ee0d
Backported to: 4.0.9, 3.2.13
The text was updated successfully, but these errors were encountered: