Skip to content

Add support for @javax.annotation.Priority as alternative to @Primary [SPR-10548] #15179

Closed
@spring-projects-issues

Description

@spring-projects-issues

Nick Williams opened SPR-10548 and commented

If multiple beans are candidates to satisfy an @Autowired/@Inject dependency, Spring looks for the @Primary annotation on one of the beans. If it finds it, it uses that bean; otherwise, it throws an exception.

javax.annotation version 1.2 (Java EE 7 and in theory Java 8) adds a new annotation to the common annotations, @Priority.

@Priority includes a single integer attribute that defines what the priority is. My suggestion is that if multiple beans are candidates to satisfy an @Autowired/@Inject dependency and @Primary is not present, Spring should look for @Priority instead. If one or more of the beans have @Priority, the one with the highest priority should be used. If two or more beans are tied for highest priority, it should behave the same as if two or more beans were @Primary.

Thoughts?


Affects: 4.0 M1

Issue Links:

1 votes, 7 watchers

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions