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:
Sam Brannen opened SPR-14060 and commented
Overview
Once #18630 is resolved it will be possible to compose
@Autowiredwith@Qualifier.Consequently, the following common combination of
@Autowiredand@Qualifier:... can be replaced with:
Although this may not appear immediately beneficial for DI for fields or setter methods, it becomes much more appealing once
@Autowiredcan 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.
Proposal
Implement
@Autowiredas follows.Issue Links:
@Autowiredto be declared on parameters