Order ManagementContextConfiguration classes without loading them

Previously, ManagementContextConfiguration classes were loaded to
allow them to be ordered based on either @Order or implementing
Ordered. This had the unwanted side-effect of possibly logging
unwanted INFO messages if the reflection-based annotation
introspection failed. One cause of this was @ConditionalOnClass when
the referenced class was not on the classpath.

This commit uses the ASM-based annotation metadata reading to
determine the order of a management context configuration class based
on the @Order annotation. The classes are then sorted using a standard
OrderComparator. Note that Ordering via implemented Ordered is not
supported as it cannot be determine without loading the class.
This commit is contained in:
Andy Wilkinson
2017-01-26 19:48:10 +00:00
parent bd0c1cb9c3
commit f3b9b14b8e
3 changed files with 85 additions and 22 deletions

View File

@@ -29,6 +29,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* Tests for {@link ManagementContextConfigurationsImportSelector}.
*
* @author Phillip Webb
* @author Andy Wilkinson
*/
public class ManagementContextConfigurationsImportSelectorTests {
@@ -37,7 +38,7 @@ public class ManagementContextConfigurationsImportSelectorTests {
String[] imports = new TestManagementContextConfigurationsImportSelector()
.selectImports(null);
assertThat(imports).containsExactly(A.class.getName(), B.class.getName(),
C.class.getName());
C.class.getName(), D.class.getName());
}
private static class TestManagementContextConfigurationsImportSelector
@@ -45,7 +46,8 @@ public class ManagementContextConfigurationsImportSelectorTests {
@Override
protected List<String> loadFactoryNames() {
return Arrays.asList(C.class.getName(), A.class.getName(), B.class.getName());
return Arrays.asList(C.class.getName(), A.class.getName(), D.class.getName(),
B.class.getName());
}
}
@@ -65,4 +67,8 @@ public class ManagementContextConfigurationsImportSelectorTests {
}
static class D {
}
}