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

Cannot autowire qualified scoped-proxy @Bean definitions [SPR-11116] #15742

Closed
spring-projects-issues opened this issue Nov 25, 2013 · 12 comments
Assignees
Labels
status: backported An issue that has been backported to maintenance branches type: bug A general bug
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

Andreas Höhmann opened SPR-11116 and commented

The old bug spr-5911 was fixed but since spring added support for java based configuration (@Configuration, @Bean) the same problem still exists (I guess).

I can't autowire qualified @Bean's.


Affects: 3.2.3, 3.2.5

Reference URL: https://jira.springsource.org/browse/SPR-5911

Referenced from: commits 2a6c642, c5d7977, 6bed180, 8580d2d

Backported to: 3.2.6

@spring-projects-issues
Copy link
Collaborator Author

Andreas Höhmann commented

Autowire of qualified beans doesn't work for proxies, no matter if I'm using xml configuration or java configuration.
I created an testproject: https://github.com/ahoehma/spring-autowire-qualified-beans

@spring-projects-issues
Copy link
Collaborator Author

Andreas Höhmann commented

Update: XML based qualified beans working now (my mistake), github project updated.

@spring-projects-issues
Copy link
Collaborator Author

Andreas Höhmann commented

[fix] add support for @Qualified into org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader

  • I'm using a local copy of ConfigurationClassBeanDefinitionReader
  • for each @Bean method all direct / indirect @Qualifier add AutowireCandidateQualifier to beanDef

Have a look at ahoehma/spring-autowire-qualified-beans@2547475

@spring-projects-issues
Copy link
Collaborator Author

Andreas Höhmann commented

Is it possible to fix this issue for spring 3.2.X too?

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

I can confirm that @Bean qualifiers work for regular bean definitions and for non-proxied scoped beans, but not for scoped proxies. I'm researching a few variants to address this, ideally without having to copy qualifier annotation metadata into the BeanDefinition. If we can find a simple enough solution without a serious risk for side effects, we'll backport it to 3.2.6 as well.

Juergen

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

Fixed for 4.0 GA, detecting qualifier annotations as well as a generic return type declaration on scoped-proxy factory methods. We've been missing tests for scoped-proxy @Bean methods before which is why we haven't found out earlier.

I've backported the qualifier annotations fix to 3.2.6 as well, since it turned out to be based on our existing decoratedDefinition mechanism, with limited effects on the rest of the codebase. 3.2.6 will be released a week after 4.0 GA.

Juergen

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

Andreas,

Could you give this an early try within the next few days maybe? Simply run against 4.0.0.BUILD-SNAPSHOT or 3.2.6.BUILD-SNAPSHOT (see http://projects.spring.io/spring-framework/)

Juergen

@spring-projects-issues
Copy link
Collaborator Author

Andreas Höhmann commented

Great. I will try it :)

@spring-projects-issues
Copy link
Collaborator Author

Andreas Höhmann commented

I have some tests in my sample project: https://github.com/ahoehma/spring-autowire-qualified-beans .., feel free to use the code :)

@spring-projects-issues
Copy link
Collaborator Author

Andreas Höhmann commented

And please check that custom annotations (i.e @Offline) with @Qualifier also work with scoped proxies. Thanks :)

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

We have all standard cases covered in the unit tests now, so we should be safe from that side. However, I'm still interested in a test within your real-life project - just as a confirmation.

If you're using Maven, testing your project against a Spring snapshot should be a straightforward version change in your POM (see http://projects.spring.io/spring-framework/ for repo metadata).

Juergen

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Jan 16, 2014

Lari Hotari commented

This issue might be related to #15871, since the #15742 changes in Spring 3.2.6.RELEASE seem to have fixed problems in Grails related to @Autowired field autowiring. The symptoms were like the ones in #15871, but I assume the problems were fixed by commit 6bed180 .
The Grails issue is http://jira.grails.org/browse/GRAILS-10991 .
It's a problem with invalid InjectionMetadata returned from the cache in AutowiredAnnotationBeanPostProcessor (shows up as java.lang.IllegalArgumentException: Can not set com.other.ExampleBean field com.example.TestForAurowiringService.testService to com.example.ExampleService because return entry is the incorrect one), but this problem cannot be reproduced on Spring 3.2.6.RELEASE.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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