-
Notifications
You must be signed in to change notification settings - Fork 38.3k
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
@Order on nested @Configuration bug #30750
Comments
@bclozel any feedback? |
Revisiting the ordering affect for configuration classes along with documenting the current behavior in #30177. Generally speaking, ordering among configuration classes is not meant to be a hard declaration - in particular not for bean overrides by name in those configuration classes -, just a soft ordering between otherwise arbitrary or name-based registration order. |
The effect that you are seeing comes from the classpath scan finding the nested classes directly rather than through their containing class. As a consequence, it processes them in the order that it found them in the classpath. Through declaring those nested classes as non-static, classpath scanning does not consider them as independent anymore, so they will actually be processed through their containing class then - with the order for nested classes respected there. You can achieve the same effect by removing the As a recommendation, if you rely on ordering for any such structure, do not use classpath scanning at all for that part. And even more generally, try to not rely on ordering at all. Bean definition overriding can be surprising even in straightforward scenarios, and such nesting with ordering for bean definition override purposes is bound to cause maintenance headaches. |
Affects: 5.2.24.RELEASE, 5.3.28, 6.0.10
Summary:
@Order
on nested@Configuration
classes is not respected in certain scenarios.Once
static
is removed, bean loading occurs as expected (and that's against what is documented for@Configuration
annotation).Here are diagrams and related code:
https://github.com/mironbalcerzak/poc-spring-config-ordering
Here's SO: https://stackoverflow.com/questions/76552375/order-ing-of-configuration-for-bean-overriding
Have a great day =)
The text was updated successfully, but these errors were encountered: