Avoid using @Order on @Configuration classes as Spring now honours it
In Spring Framework 4.1, @Order on a @Configuration class had no effect. This allowed us to use it on auto-configuration classes to control the ordering of auto-configuration classes without it having any broader implications for configuration class ordering. Spring Framework 4.2 now honours @Order on @Configuration classes. This breaks a number of tests where we were relying on the order that the classes were passed to register when evaluating various bean conditions. This commit replaces the use of @Order on auto-configuration classes with a new annotation, @AutoConfigureOrder. The new annotation is handled by AutoConfigurationSorter where it’s used to order auto-configuration classes. This allows us to order auto-configuration classes without the unwanted side-effect of this also affecting the general ordering of configuration classes. See gh-2575pull/2718/head
parent
04c5fc8856
commit
7a73c5883f
@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright 2012-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.autoconfigure;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.core.annotation.Order;
|
||||
|
||||
/**
|
||||
* Auto-configuration specific variant of Spring Framework's {@link Order} annotation.
|
||||
* Allows auto-configuration classes to be ordered among themselves without affecting the
|
||||
* order of configuration classes passed to
|
||||
* {@link AnnotationConfigApplicationContext#register(Class...)}.
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
* @since 1.3.0
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ ElementType.TYPE, ElementType.METHOD, ElementType.FIELD })
|
||||
public @interface AutoConfigureOrder {
|
||||
|
||||
/**
|
||||
* The order value. Default is {@link Ordered#LOWEST_PRECEDENCE}.
|
||||
* @see Ordered#getOrder()
|
||||
*/
|
||||
int value() default Ordered.LOWEST_PRECEDENCE;
|
||||
|
||||
}
|
Loading…
Reference in New Issue