Change default order of AutoConfigureOrder to 0
Previously, AutoConfigureOrder defaulted to Ordered.LOWEST_PRECEDENCE. This made is impossible for an individual auto-configuration to indicate that it wanted to go "last", i.e. after any auto-configuration classes that didn't not specify an order, or specified an order other than LOWEST_PRECEDENCE. This commit changes to default to 0, allowing a single auto-configuration to easily indicate that it should go last. Closes gh-10142
This commit is contained in:
parent
f49741e3ed
commit
8df852bf71
|
|
@ -26,7 +26,6 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.core.type.AnnotationMetadata;
|
||||
import org.springframework.core.type.classreading.MetadataReader;
|
||||
import org.springframework.core.type.classreading.MetadataReaderFactory;
|
||||
|
|
@ -164,11 +163,11 @@ class AutoConfigurationSorter {
|
|||
private int getOrder() {
|
||||
if (wasProcessed()) {
|
||||
return this.autoConfigurationMetadata.getInteger(this.className,
|
||||
"AutoConfigureOrder", Ordered.LOWEST_PRECEDENCE);
|
||||
"AutoConfigureOrder", AutoConfigureOrder.DEFAULT_ORDER);
|
||||
}
|
||||
Map<String, Object> attributes = getAnnotationMetadata()
|
||||
.getAnnotationAttributes(AutoConfigureOrder.class.getName());
|
||||
return (attributes == null ? Ordered.LOWEST_PRECEDENCE
|
||||
return (attributes == null ? AutoConfigureOrder.DEFAULT_ORDER
|
||||
: (Integer) attributes.get("value"));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2015 the original author or authors.
|
||||
* Copyright 2012-2017 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.
|
||||
|
|
@ -38,11 +38,13 @@ import org.springframework.core.annotation.Order;
|
|||
@Target({ ElementType.TYPE, ElementType.METHOD, ElementType.FIELD })
|
||||
public @interface AutoConfigureOrder {
|
||||
|
||||
int DEFAULT_ORDER = 0;
|
||||
|
||||
/**
|
||||
* The order value. Default is {@link Ordered#LOWEST_PRECEDENCE}.
|
||||
* The order value. Default is {@code 0}.
|
||||
* @see Ordered#getOrder()
|
||||
* @return the order value
|
||||
*/
|
||||
int value() default Ordered.LOWEST_PRECEDENCE;
|
||||
int value() default DEFAULT_ORDER;
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,9 +40,12 @@ import static org.mockito.Mockito.mock;
|
|||
* Tests for {@link AutoConfigurationSorter}.
|
||||
*
|
||||
* @author Phillip Webb
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
public class AutoConfigurationSorterTests {
|
||||
|
||||
private static final String DEFAULT = OrderUnspecified.class.getName();
|
||||
|
||||
private static final String LOWEST = OrderLowest.class.getName();
|
||||
|
||||
private static final String HIGHEST = OrderHighest.class.getName();
|
||||
|
|
@ -86,8 +89,8 @@ public class AutoConfigurationSorterTests {
|
|||
@Test
|
||||
public void byOrderAnnotation() throws Exception {
|
||||
List<String> actual = this.sorter
|
||||
.getInPriorityOrder(Arrays.asList(LOWEST, HIGHEST));
|
||||
assertThat(actual).containsExactly(HIGHEST, LOWEST);
|
||||
.getInPriorityOrder(Arrays.asList(LOWEST, HIGHEST, DEFAULT));
|
||||
assertThat(actual).containsExactly(HIGHEST, DEFAULT, LOWEST);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -193,6 +196,11 @@ public class AutoConfigurationSorterTests {
|
|||
return StringUtils.collectionToCommaDelimitedString(items);
|
||||
}
|
||||
|
||||
@AutoConfigureOrder
|
||||
public static class OrderUnspecified {
|
||||
|
||||
}
|
||||
|
||||
@AutoConfigureOrder(Ordered.LOWEST_PRECEDENCE)
|
||||
public static class OrderLowest {
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue