Skip to content

Prototype with changing bean class does not get populated with dependencies after type switch [SPR-12526] #17131

Closed
@spring-projects-issues

Description

@spring-projects-issues

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

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)status: backportedAn issue that has been backported to maintenance branchestype: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions