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

Method-based autowiring fails in certain contexts [SPR-9685] #14319

Closed
spring-projects-issues opened this issue Aug 14, 2012 · 1 comment
Closed
Labels
in: core status: declined

Comments

@spring-projects-issues
Copy link
Collaborator

@spring-projects-issues spring-projects-issues commented Aug 14, 2012

Steve van Loben Sels opened SPR-9685 and commented

If an application context contains more than one instance of a bean whose class has an @Autowired setter method, then it's possible that some of the beans' dependencies do not get injected.

The attached TestNG unit test demonstrates the bug. It creates two singletons of type AutowiredMethodBean...one from XML and the other from a @Configuration. When the bean defined in the XML is initialized first, then the JavaConfig's bean will not be autowired and the test will fail. The order in which the beans are instantiated is crucial...the test passes if the JavaConfig bean is created first.

This problem looks to be due to the cached metadata in AutowiredAnnotationBeanPostProcessor. If the metadata is lazily created when initializing the XML bean with its explicit property declaration, then the field is marked as skipped and injection won't be attempted on the JavaConfig bean.

This unit test uses a mixed XML/JavaConfig application context because that's the configuration of the application I was working on when I discovered the issue. I suspect that it's possible to manifest with XML-only configuration if the first bean has the property explicitly set and the second uses autowiring.


Affects: 3.1.2

Attachments:

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Dec 28, 2018

Sébastien Deleuze commented

Closing groups of outdated issues. Please reopen if still relevant.

@spring-projects-issues spring-projects-issues added type: bug status: declined in: core and removed type: bug labels Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core status: declined
Projects
None yet
Development

No branches or pull requests

1 participant