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

@Resource injection broken under spring-framework > 4.1.0 [SPR-12490] #17096

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

Doug Davies opened SPR-12490 and commented

@Resource injection seems to behave differently between spring-framework 4.1.0 and 4.1.1 because it thinks a method in a class extended from an abstract class is a bridge and it never calls the setter.

For example

abstract class AbstractComponent {
    @Resource
    public void setHttpServletRequest(final HttpServletRequest request) {
        System.out.println("Setting HttpServletRequest");
    }
}

@Component
public final class RealComponent extends AbstractComponent {
}

If I change the @Resource to @Autowired then it works as expected.

I think the change that broke this is

f4219ca#diff-2

It was to resolve #16801

I have provided a complete spring-boot project that demonstrates the issue at

https://github.com/funkyvisions/spring-boot-hello-world


Affects: 4.1.1, 4.1.2

Reference URL: http://stackoverflow.com/questions/27234508/resource-injection-broken-under-spring-framework-4-1-0

Issue Links:

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

This might be a "visibility bridge method" scenario since your base class isn't public... If you do declare it as public, @Resource might work fine as well?

In any case, there is an inconsistency in the bridge method handling code between @AutowiredAnnotationBeanPostProcessor and CommonAnnotationBeanPostProcessor; I'm going to fix this for 4.1.3.

Juergen

@spring-projects-issues
Copy link
Collaborator Author

Doug Davies commented

You are correct. Making the abstract class public also fixes the problem.

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

2 participants