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

@Required doesn't play nice with @Configuration and @Bean [SPR-5744] #10414

Closed
spring-projects-issues opened this issue May 11, 2009 · 1 comment
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

Kenny MacLeod opened SPR-5744 and commented

I've been using M3 to try porting fragments of existing applications to use @Configuration and @Bean instead of XML bean definitions. The bean classes make heavy use of @Required. When I try to configure one of these beans using annotations, and injecting collaborators java-style, the context fails to start up, saying that a @Required property has not been set.

This is a problem, because these existing application classes are used everywhere, mostly using the @Required annotation in conjunction with XML bean definitions. Also, the context:component-scan tag which is used to locate the @Configuration classes implicitly adds a RequiredAnnotationBeanPostProcessor to the context.

It's not clear how to handle this, unless the framework can automagically figure out that the @Bean method is injecting the collaborators.

I've created a standalone test case illustrating the problem.


Affects: 3.0 M3

Attachments:

Referenced from: commits c7b019c

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

Good point! I've simply suppressed @Required processing for beans returned by @Bean factory methods. We cannot reliably check whether the property has been injected in that case; arguably @Required isn't really designed for that purpose to begin with. However, it shouldn't cause failures either.

Juergen

@spring-projects-issues spring-projects-issues added type: enhancement A general enhancement 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 3.0 M4 milestone 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) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants