Skip to content

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

@spring-projects-issues

Description

@spring-projects-issues

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:

Metadata

Metadata

Assignees

No one assigned

    Labels

    in: coreIssues in core modules (aop, beans, core, context, expression)type: bugA general bug

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions