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

Annotation based injection into non public base classes does not work [SPR-7900] #12555

Closed
spring-projects-issues opened this issue Jan 21, 2011 · 3 comments
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: bug A general bug
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Jan 21, 2011

Andreas Benneke opened SPR-7900 and commented

Annotation driven injection on public methods specified in a non-public base classes does not work, because Java generates bridge methods for the subclass which are not ignored by Spring (as they should IMHO).

Example:

/* not public! */ class Base {

	@Resource
	public void setResource(Injectable injectable) {
           ...
	}
}

@Component
public class Target extends Base {

}

Same applies to @Autowired.

The attached maven project demonstrates this.

Workarounds: Use field injection, re-declare the method(s) in the subclass or make the base class public.


Affects: 3.0.5

Attachments:

Issue Links:

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Jun 10, 2011

Stefan Gybas commented

This used to work on Java 5. I have created another issue (#13080) because I did not find this issue in my first search.

@spring-projects-issues
Copy link
Collaborator Author

Chris Beams commented

Andreas,

Thanks for the test project. I'm reproducing this locally and we'll definitely patch things up here. Scheduling for inclusion in 3.0.6 as well as 3.1 RC1 as the fix will likely be worth backporting.

@spring-projects-issues
Copy link
Collaborator Author

Chris Beams commented

Author: Chris Beams <cbeams@vmware.com>
Date:   Tue Jun 21 22:23:54 2011 +0800

    Fix bridge method detection for class hierarchies
    
    Prior to this change, @Autowired injection against an instance of a
    subclass having different visibility than its superclass would fail
    if the @Autowired method is declared only in the superclass. This is due
    to an apparent change in the rules around bridge method generation
    between Java 5 and Java 6, and possibly even varying across compiler
    vendors.
    
    Now, BridgeMethodResolver is used consistently when detecting
    @Autowired, @Inject and @Resource metadata to bypass these bridge
    methods if they exist.
    
    Issue: SPR-7900

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: bug A general bug
Projects
None yet
Development

No branches or pull requests

1 participant