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
As of 4.2, we sort all top-level configuration class candidates by @Order value (note: just the annotation, with the Ordered interface not supported for this purpose) before starting to process them. Any imported or otherwise lazily determined configuration classes will be processed in the regular order of registration, since they are not part of the initial ordering.
This change has broken a number of tests in Spring Boot due to its use of @Order to order auto-configuration classes in its DeferredImportSelector. It's a deferred import selector as we always want auto-configuration classes to be processed after any other configuration. This should, I believe, still work fine in normal running but causes problems in our tests.
A typical test doesn't use the import selector but simply relies on the configuration registration order being honoured. For example:
The ordering here is deliberate. MultipartConfiguration needs to be processed before the two auto-configuration classes. Unfortunately, DispatcherServletAutoConfiguration is annotated with @Order(Ordered.HIGHEST_PRECEDENCE) so, when we use Spring Framework 4.2, it's processed before MultipartConfiguration which causes the test to fail.
We could change Spring Boot to work around this behaviour change, but Stephane encouraged me to comment here in case there's anything that can be done in the framework .
Why is DispatcherServletAutoConfiguration annotated with @Order then? In which context was it meant to be significant?
I'm afraid there's not much we can do about it since the whole point of this change is that @Order becomes significant among configuration classes. I suppose we could somehow specifically order Boot's auto-configuration classes after regular configuration classes... We'd need a framework-level marker for auto-config classes then though, since currently the framework is unaware of that distinction.
The @Order on DispatcherServletAutoConfiguration is processed by Boot's AutoConfigurationSorter. It determines the ordering of auto-configuration classes returned from EnableAutoConfigurationImportSelector.selectImports. That worked fine in 4.1, but now has the side-effect of changing the order when the classes are passed directly to register in our tests.
I've prototyped a change that introduces @AutoConfigureOrder (alongside the existing @AutoConfigureBefore and @AutoConfigureAfter) to be used in place of @Order on auto-configuration classes.
I'm not aware of a regression here... We process @PropertySource along with each individual configuration class, so the behavior should simply follow configuration class ordering, and then the property source composition rules within that - just like when you manually registered your configuration classes in that order.
I want use @Order control @PropertySource overriding, It is useful to define default @PropertySource in base framework and let applications to override it if necessary. I tested with 4.2.3 and it doesn't works, this issue is not resolved and should be reopen.
Could you please sketch a test for a case that you'd expect to work but which doesn't?
Keep in mind that @Order controls the order of processing, just like when relying on the order of registration in a setup without component scan. In other words, if your property source overriding works with explicit AnnotationConfigApplicationContext.register calls, it should also work with classpath scanning (and its unpredictability) as long as the @Order values on your configuration values suggest the same order.
Activity
spring-projects-issues commentedon Mar 13, 2015
Juergen Hoeller commented
As of 4.2, we sort all top-level configuration class candidates by
@Ordervalue (note: just the annotation, with theOrderedinterface not supported for this purpose) before starting to process them. Any imported or otherwise lazily determined configuration classes will be processed in the regular order of registration, since they are not part of the initial ordering.Juergen
spring-projects-issues commentedon Mar 24, 2015
Andy Wilkinson commented
This change has broken a number of tests in Spring Boot due to its use of
@Orderto order auto-configuration classes in itsDeferredImportSelector. It's a deferred import selector as we always want auto-configuration classes to be processed after any other configuration. This should, I believe, still work fine in normal running but causes problems in our tests.A typical test doesn't use the import selector but simply relies on the configuration registration order being honoured. For example:
The ordering here is deliberate.
MultipartConfigurationneeds to be processed before the two auto-configuration classes. Unfortunately,DispatcherServletAutoConfigurationis annotated with@Order(Ordered.HIGHEST_PRECEDENCE)so, when we use Spring Framework 4.2, it's processed beforeMultipartConfigurationwhich causes the test to fail.We could change Spring Boot to work around this behaviour change, but Stephane encouraged me to comment here in case there's anything that can be done in the framework .
spring-projects-issues commentedon Mar 24, 2015
Juergen Hoeller commented
Why is
DispatcherServletAutoConfigurationannotated with@Orderthen? In which context was it meant to be significant?I'm afraid there's not much we can do about it since the whole point of this change is that
@Orderbecomes significant among configuration classes. I suppose we could somehow specifically order Boot's auto-configuration classes after regular configuration classes... We'd need a framework-level marker for auto-config classes then though, since currently the framework is unaware of that distinction.Juergen
spring-projects-issues commentedon Mar 24, 2015
Andy Wilkinson commented
The
@OrderonDispatcherServletAutoConfigurationis processed by Boot'sAutoConfigurationSorter. It determines the ordering of auto-configuration classes returned fromEnableAutoConfigurationImportSelector.selectImports. That worked fine in 4.1, but now has the side-effect of changing the order when the classes are passed directly toregisterin our tests.I've prototyped a change that introduces
@AutoConfigureOrder(alongside the existing@AutoConfigureBeforeand@AutoConfigureAfter) to be used in place of@Orderon auto-configuration classes.spring-projects-issues commentedon Jun 24, 2015
Matt Benson commented
What direction did
spring-bootend up taking on this? I have opened spring-cloud/spring-cloud-commons#40, which relates.spring-projects-issues commentedon Jun 24, 2015
Andy Wilkinson commented
We use
@AutoConfigureOrderrather than@Orderon our auto-configuration classes now. See this commit for the details.spring-projects-issues commentedon Dec 10, 2015
Yanming Zhou commented
It seems
@PropertySourceand@PropertySourcespriority doesn't respect@Order, tested with 4.2.3, is it a regression or never fixed ?spring-projects-issues commentedon Dec 10, 2015
Juergen Hoeller commented
I'm not aware of a regression here... We process
@PropertySourcealong with each individual configuration class, so the behavior should simply follow configuration class ordering, and then the property source composition rules within that - just like when you manually registered your configuration classes in that order.Juergen
spring-projects-issues commentedon Dec 11, 2015
Yanming Zhou commented
I want use
@Ordercontrol@PropertySourceoverriding, It is useful to define default@PropertySourcein base framework and let applications to override it if necessary. I tested with 4.2.3 and it doesn't works, this issue is not resolved and should be reopen.spring-projects-issues commentedon Dec 11, 2015
Juergen Hoeller commented
Could you please sketch a test for a case that you'd expect to work but which doesn't?
Keep in mind that
@Ordercontrols the order of processing, just like when relying on the order of registration in a setup without component scan. In other words, if your property source overriding works with explicitAnnotationConfigApplicationContext.registercalls, it should also work with classpath scanning (and its unpredictability) as long as the@Ordervalues on your configuration values suggest the same order.Juergen
spring-projects-issues commentedon Dec 11, 2015
Yanming Zhou commented
Sorry for my fault, It works �fine, my test failed because the key exists in system property and placeholder always resolved with system property.