diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/EnableAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/EnableAutoConfiguration.java index ae9fed26b1d..dca59dca18e 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/EnableAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/EnableAutoConfiguration.java @@ -75,15 +75,6 @@ import org.springframework.core.io.support.SpringFactoriesLoader; AutoConfigurationPackages.Registrar.class }) public @interface EnableAutoConfiguration { - /** - * Include only the specified auto-configuration classes and do not attempt full - * auto-configuration. Using this attribute means that {@code spring.factories} files - * will not be considered. This attribute should not generally be specified in - * production applications, however, it is useful for tests. - * @return the classes to include - */ - Class[] include() default {}; - /** * Exclude specific auto-configuration classes such that they will never be applied. * @return the classes to exclude diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/EnableAutoConfigurationImportSelector.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/EnableAutoConfigurationImportSelector.java index 37c643c05d6..bcb27ca79d6 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/EnableAutoConfigurationImportSelector.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/EnableAutoConfigurationImportSelector.java @@ -75,12 +75,14 @@ class EnableAutoConfigurationImportSelector implements DeferredImportSelector, + " annotated with @EnableAutoConfiguration?"); // Find all possible auto configuration classes, filtering duplicates - List factories = getFactories(attributes); + List factories = new ArrayList(new LinkedHashSet( + SpringFactoriesLoader.loadFactoryNames(EnableAutoConfiguration.class, + this.beanClassLoader))); // Remove those specifically excluded Set excluded = new LinkedHashSet(); - excluded.addAll(asList(attributes, "exclude")); - excluded.addAll(asList(attributes, "excludeName")); + excluded.addAll(Arrays.asList(attributes.getStringArray("exclude"))); + excluded.addAll(Arrays.asList(attributes.getStringArray("excludeName"))); excluded.addAll(getExcludeAutoConfigurationsProperty()); factories.removeAll(excluded); ConditionEvaluationReport.get(this.beanFactory).recordExclusions(excluded); @@ -98,20 +100,6 @@ class EnableAutoConfigurationImportSelector implements DeferredImportSelector, } } - private List getFactories(AnnotationAttributes attributes) { - List factories = asList(attributes, "include"); - if (factories.isEmpty()) { - factories = SpringFactoriesLoader.loadFactoryNames( - EnableAutoConfiguration.class, this.beanClassLoader); - } - return new ArrayList(new LinkedHashSet(factories)); - } - - private List asList(AnnotationAttributes attributes, String name) { - String[] value = attributes.getStringArray(name); - return Arrays.asList(value == null ? new String[0] : value); - } - private List getExcludeAutoConfigurationsProperty() { RelaxedPropertyResolver resolver = new RelaxedPropertyResolver(this.environment, "spring.autoconfigure."); diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/EnableAutoConfigurationImportSelectorTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/EnableAutoConfigurationImportSelectorTests.java index 4409c769fcc..e24edb5634c 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/EnableAutoConfigurationImportSelectorTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/EnableAutoConfigurationImportSelectorTests.java @@ -148,18 +148,6 @@ public class EnableAutoConfigurationImportSelectorTests { ThymeleafAutoConfiguration.class.getName())); } - @Test - public void classIncludesAreApplied() throws Exception { - given( - this.annotationMetadata.getAnnotationAttributes( - EnableAutoConfiguration.class.getName(), true)).willReturn( - this.annotationAttributes); - given(this.annotationAttributes.getStringArray("include")).willReturn( - new String[] { FreeMarkerAutoConfiguration.class.getName() }); - String[] imports = this.importSelector.selectImports(this.annotationMetadata); - assertThat(imports.length, is(equalTo(1))); - } - private void configureExclusions(String[] classExclusion, String[] nameExclusion, String[] propertyExclusion) { given( @@ -180,5 +168,4 @@ public class EnableAutoConfigurationImportSelectorTests { return SpringFactoriesLoader.loadFactoryNames(EnableAutoConfiguration.class, getClass().getClassLoader()); } - } diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/context/ConfigurationPropertiesAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/context/ConfigurationPropertiesAutoConfigurationTests.java index 736542dbf68..9c3c24d1ce4 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/context/ConfigurationPropertiesAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/context/ConfigurationPropertiesAutoConfigurationTests.java @@ -18,11 +18,9 @@ package org.springframework.boot.autoconfigure.context; import org.junit.After; import org.junit.Test; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.test.EnvironmentTestUtils; import org.springframework.context.annotation.AnnotationConfigApplicationContext; -import org.springframework.context.annotation.Configuration; import org.springframework.stereotype.Component; import static org.hamcrest.core.Is.is; @@ -46,7 +44,8 @@ public class ConfigurationPropertiesAutoConfigurationTests { @Test public void processAnnotatedBean() { - load(new Class[] { AutoConfigured.class, SampleBean.class }, "foo.name:test"); + load(new Class[] { SampleBean.class, + ConfigurationPropertiesAutoConfiguration.class }, "foo.name:test"); assertThat(this.context.getBean(SampleBean.class).getName(), is("test")); } @@ -63,12 +62,6 @@ public class ConfigurationPropertiesAutoConfigurationTests { this.context.refresh(); } - @Configuration - @EnableAutoConfiguration(include = ConfigurationPropertiesAutoConfiguration.class) - static class AutoConfigured { - - } - @Component @ConfigurationProperties("foo") static class SampleBean {