-
Notifications
You must be signed in to change notification settings - Fork 6k
@Order annotations cannot be used with @Bean methods #9154
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
Comments
@philwebb We had an existing test checking the order on |
@eleftherias I'm afraid not, it was just an observation from looking at the code. I may well have got it wrong. Perhaps Spring is injecting the list already sorted and re-sorting it doesn't cause a side-effect. I'll close this one since the tests seem to prove it's working. |
@eleftherias Here is an example where Spring Security's sort will flip the order that Spring Framework injected them in: @Bean
@Order(1)
SecurityFilterChain securityFilterChain1(HttpSecurity http) throws Exception {
//something
return http.build();
}
@Bean
TestSecurityFilterChain securityFilterChain2(HttpSecurity http) throws Exception {
return new TestSecurityFilterChain();
}
@Order(2)
static class TestSecurityFilterChain implements SecurityFilterChain {
//implement methods
} Spring Framework will inject |
Thanks for the sample @mbhave. I'm reopening the issue. |
Whilst looking at spring-projects/spring-boot#23421 I noticed a few of our migrations use the
@Order
annotation on beans.A common pattern would be:
and
I'm not convinced that these
@Order
annotations are working in these locations (or perhaps they're not supposed to be used that way).Looking at the code, I think
WebSecurityConfiguration.setWebSecurityCustomizers
andWebSecurityConfiguration.setFilterChains
are responsible for managing the beans and they sort items directly. I'm pretty sure that this doesn't consider any annotations on the@Bean
method.I think that using
ObjectProvider.orderedStream()
might be a better choice since it will wire up aFactoryAwareOrderSourceProvider
OrderComparator.OrderSourceProvider
The text was updated successfully, but these errors were encountered: