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

Compose @Autowired with @Qualifier [SPR-14060] #18632

Closed
spring-projects-issues opened this issue Mar 16, 2016 · 2 comments
Closed

Compose @Autowired with @Qualifier [SPR-14060] #18632

spring-projects-issues opened this issue Mar 16, 2016 · 2 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: declined A suggestion or change that we don't feel we should currently apply type: enhancement A general enhancement

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Mar 16, 2016

Sam Brannen opened SPR-14060 and commented

Overview

Once #18630 is resolved it will be possible to compose @Autowired with @Qualifier.

Consequently, the following common combination of @Autowired and @Qualifier:

@Autowired
@Qualifier("holidayDateService")
private DateService dateService;

... can be replaced with:

@Autowired("holidayDateService")
private DateService dateService;

Although this may not appear immediately beneficial for DI for fields or setter methods, it becomes much more appealing once @Autowired can be applied to parameters (see #18629).

For example, Spring's testing support for JUnit 5 would then be able to support parameter injection succinctly in test methods as follows.

@Test
void businessHolidays(@Autowired("holidayDateService") DateService dateService) {
}

Proposal

Implement @Autowired as follows.

@Target({ElementType.CONSTRUCTOR, ElementType.FIELD, ElementType.METHOD, ElementType.ANNOTATION_TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Qualifier
public @interface Autowired {

	@AliasFor(annotation = Qualifier.class, attribute = "value")
	String value() default "";

	@AliasFor(annotation = Qualifier.class, attribute = "value")
	String qualifier() default "";

	boolean required() default true;

}

Issue Links:

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Mar 16, 2016

Sam Brannen commented

This issue depends on #18630.

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Mar 16, 2016

Sam Brannen commented

For various reasons, the team has decided not to compose @Autowired with @Qualifier. I am therefore resolving this issue as Won't Fix.

@spring-projects-issues spring-projects-issues added status: declined A suggestion or change that we don't feel we should currently apply type: enhancement A general enhancement in: core Issues in core modules (aop, beans, core, context, expression) labels 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) status: declined A suggestion or change that we don't feel we should currently apply type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants