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

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

Closed
spring-projects-issues opened this issue Dec 9, 2014 · 2 comments
Assignees
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

Comments

@spring-projects-issues
Copy link
Collaborator

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

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

It turns out that the culprit was in annotation post-processors' metadata caching: Setter methods may get registered as "processed properties" with the bean's BeanDefinition, preventing multiple invocations from multiple post-processors... On metadata refresh, such as in the case of a changing bean type, those "processed properties" weren't cleared so the post-processor thought somebody else would process the property already. This only affects same-named setter methods across changing bean types; different method names would have led to different property keys, with no false detection of pre-processed properties. In any case, this has been fixed for 4.1.4 now and will be backported to 4.0.9 / 3.2.13.

Juergen

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

If you have the chance, it would be great if you could give this an early try against the latest 4.1.4 snapshot...

Juergen

@spring-projects-issues spring-projects-issues added type: bug A general bug status: backported An issue that has been backported to maintenance branches in: core Issues in core modules (aop, beans, core, context, expression) labels Jan 11, 2019
@spring-projects-issues spring-projects-issues added this to the 4.1.4 milestone Jan 11, 2019
This was referenced Jan 11, 2019
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) status: backported An issue that has been backported to maintenance branches type: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants