Skip to content

Commit 8df852b

Browse files
committed
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
1 parent f49741e commit 8df852b

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationSorter.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import java.util.Map;
2727
import java.util.Set;
2828

29-
import org.springframework.core.Ordered;
3029
import org.springframework.core.type.AnnotationMetadata;
3130
import org.springframework.core.type.classreading.MetadataReader;
3231
import org.springframework.core.type.classreading.MetadataReaderFactory;
@@ -164,11 +163,11 @@ public Set<String> getAfter() {
164163
private int getOrder() {
165164
if (wasProcessed()) {
166165
return this.autoConfigurationMetadata.getInteger(this.className,
167-
"AutoConfigureOrder", Ordered.LOWEST_PRECEDENCE);
166+
"AutoConfigureOrder", AutoConfigureOrder.DEFAULT_ORDER);
168167
}
169168
Map<String, Object> attributes = getAnnotationMetadata()
170169
.getAnnotationAttributes(AutoConfigureOrder.class.getName());
171-
return (attributes == null ? Ordered.LOWEST_PRECEDENCE
170+
return (attributes == null ? AutoConfigureOrder.DEFAULT_ORDER
172171
: (Integer) attributes.get("value"));
173172
}
174173

spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigureOrder.java

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2015 the original author or authors.
2+
* Copyright 2012-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -38,11 +38,13 @@
3838
@Target({ ElementType.TYPE, ElementType.METHOD, ElementType.FIELD })
3939
public @interface AutoConfigureOrder {
4040

41+
int DEFAULT_ORDER = 0;
42+
4143
/**
42-
* The order value. Default is {@link Ordered#LOWEST_PRECEDENCE}.
44+
* The order value. Default is {@code 0}.
4345
* @see Ordered#getOrder()
4446
* @return the order value
4547
*/
46-
int value() default Ordered.LOWEST_PRECEDENCE;
48+
int value() default DEFAULT_ORDER;
4749

4850
}

spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/AutoConfigurationSorterTests.java

+10-2
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,12 @@
4040
* Tests for {@link AutoConfigurationSorter}.
4141
*
4242
* @author Phillip Webb
43+
* @author Andy Wilkinson
4344
*/
4445
public class AutoConfigurationSorterTests {
4546

47+
private static final String DEFAULT = OrderUnspecified.class.getName();
48+
4649
private static final String LOWEST = OrderLowest.class.getName();
4750

4851
private static final String HIGHEST = OrderHighest.class.getName();
@@ -86,8 +89,8 @@ public void setup() {
8689
@Test
8790
public void byOrderAnnotation() throws Exception {
8891
List<String> actual = this.sorter
89-
.getInPriorityOrder(Arrays.asList(LOWEST, HIGHEST));
90-
assertThat(actual).containsExactly(HIGHEST, LOWEST);
92+
.getInPriorityOrder(Arrays.asList(LOWEST, HIGHEST, DEFAULT));
93+
assertThat(actual).containsExactly(HIGHEST, DEFAULT, LOWEST);
9194
}
9295

9396
@Test
@@ -193,6 +196,11 @@ private String merge(Class<?>[] value, String[] name) {
193196
return StringUtils.collectionToCommaDelimitedString(items);
194197
}
195198

199+
@AutoConfigureOrder
200+
public static class OrderUnspecified {
201+
202+
}
203+
196204
@AutoConfigureOrder(Ordered.LOWEST_PRECEDENCE)
197205
public static class OrderLowest {
198206

0 commit comments

Comments
 (0)