-
Notifications
You must be signed in to change notification settings - Fork 38.8k
Description
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:
- NPE in DefaultListableBeanFactory#getPriority [SPR-12024] #16640 NPE in DefaultListableBeanFactory#getPriority
- Document common use cases for @Order vs @Priority vs @DependsOn [SPR-16213] #20761 Document common use cases for
@Ordervs@Priorityvs@DependsOn - Use javax.annotation.Priority as an alternative for @Order [SPR-11639] #16262 Use javax.annotation.Priority as an alternative for
@Order
1 votes, 7 watchers