diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationSorter.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationSorter.java index b048908acac..b6c5570cdae 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationSorter.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationSorter.java @@ -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 attributes = getAnnotationMetadata() .getAnnotationAttributes(AutoConfigureOrder.class.getName()); - return (attributes == null ? Ordered.LOWEST_PRECEDENCE + return (attributes == null ? AutoConfigureOrder.DEFAULT_ORDER : (Integer) attributes.get("value")); } diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigureOrder.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigureOrder.java index f861648a2dc..5e983a4131d 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigureOrder.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigureOrder.java @@ -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; } diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/AutoConfigurationSorterTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/AutoConfigurationSorterTests.java index 6d2b009c1a2..c664ba0384f 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/AutoConfigurationSorterTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/AutoConfigurationSorterTests.java @@ -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 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 {