You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Support for @Order at the @Bean method level [SPR-11310] #15934
This won't order the wired list. Since AnnotationAwareOrderComparator only scan the Type annotations instead of Method annotations.
@Bean
@Order(2)
public Store getStore2(){
return new Store();
}
@Bean
@Order(1)
public Store getStore1(){
return new Store();
}
@Bean
@Order(3)
public Store getStore3(){
return new Store();
}
I understand the confusion but @Order has a specific note about this use case. In your case, you want a different priority for the same Class. Your Store class should implement org.springframework.core.Ordered so that you can set the order instance per instance, e.g.
Indeed, this is a traditional @Order limitation. Ordering injected bean arrays and collections based on such order values is a new feature in 4.0 now, but basically inherits that AnnotationAwareOrderComparator limitation.
That said, with a little bit of extra context for the comparator, we should be able to respect @Order values on factory methods as well. Let's research this for 4.1.
This is available on master in the next hour or so in 4.1.0.BUILD-SNAPSHOT for you to try.
Introduced OrderProvider and OrderProviderComparator, the latter allowing to sort a collection of elements according to a given OrderProvider instance.
In practice, we have a specific OrderProvider implementation that is able to retrieve the bean definition of a given value, checking on its factory method, if any, if an order has been specified. Such @Order declaration takes precedence and can be specified in a meta-annotation if necessary.
Activity
spring-projects-issues commentedon Jan 14, 2014
Stéphane Nicoll commented
I understand the confusion but
@Orderhas a specific note about this use case. In your case, you want a different priority for the sameClass. YourStoreclass should implementorg.springframework.core.Orderedso that you can set the order instance per instance, e.g.Hope that helps.
spring-projects-issues commentedon Jan 14, 2014
Juergen Hoeller commented
Indeed, this is a traditional
@Orderlimitation. Ordering injected bean arrays and collections based on such order values is a new feature in 4.0 now, but basically inherits that AnnotationAwareOrderComparator limitation.That said, with a little bit of extra context for the comparator, we should be able to respect
@Ordervalues on factory methods as well. Let's research this for 4.1.Juergen
spring-projects-issues commentedon Jun 4, 2014
Stéphane Nicoll commented
This is available on master in the next hour or so in
4.1.0.BUILD-SNAPSHOTfor you to try.Introduced
OrderProviderandOrderProviderComparator, the latter allowing to sort a collection of elements according to a givenOrderProviderinstance.In practice, we have a specific
OrderProviderimplementation that is able to retrieve the bean definition of a given value, checking on its factory method, if any, if an order has been specified. Such@Orderdeclaration takes precedence and can be specified in a meta-annotation if necessary.