|
|
|
|
@ -29,10 +29,8 @@ import org.springframework.beans.factory.BeanFactory;
@@ -29,10 +29,8 @@ import org.springframework.beans.factory.BeanFactory;
|
|
|
|
|
import org.springframework.beans.factory.BeanFactoryAware; |
|
|
|
|
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; |
|
|
|
|
import org.springframework.beans.factory.support.DefaultListableBeanFactory; |
|
|
|
|
import org.springframework.boot.autoconfigure.freemarker.FreeMarkerAutoConfiguration; |
|
|
|
|
import org.springframework.boot.autoconfigure.mustache.MustacheAutoConfiguration; |
|
|
|
|
import org.springframework.boot.autoconfigure.thymeleaf.ThymeleafAutoConfiguration; |
|
|
|
|
import org.springframework.boot.context.annotation.ImportCandidates; |
|
|
|
|
import org.springframework.boot.testsupport.classpath.resources.WithResource; |
|
|
|
|
import org.springframework.context.annotation.Configuration; |
|
|
|
|
import org.springframework.core.io.DefaultResourceLoader; |
|
|
|
|
import org.springframework.core.type.AnnotationMetadata; |
|
|
|
|
@ -48,6 +46,15 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
@@ -48,6 +46,15 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
|
|
|
|
* @author Stephane Nicoll |
|
|
|
|
* @author Madhura Bhave |
|
|
|
|
*/ |
|
|
|
|
@WithResource(name = "META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports", content = """ |
|
|
|
|
com.example.one.FirstAutoConfiguration |
|
|
|
|
com.example.two.SecondAutoConfiguration |
|
|
|
|
com.example.three.ThirdAutoConfiguration |
|
|
|
|
com.example.four.FourthAutoConfiguration |
|
|
|
|
com.example.five.FifthAutoConfiguration |
|
|
|
|
com.example.six.SixthAutoConfiguration |
|
|
|
|
org.springframework.boot.autoconfigure.AutoConfigurationImportSelectorTests$SeventhAutoConfiguration |
|
|
|
|
""") |
|
|
|
|
class AutoConfigurationImportSelectorTests { |
|
|
|
|
|
|
|
|
|
private final TestAutoConfigurationImportSelector importSelector = new TestAutoConfigurationImportSelector(); |
|
|
|
|
@ -63,6 +70,7 @@ class AutoConfigurationImportSelectorTests {
@@ -63,6 +70,7 @@ class AutoConfigurationImportSelectorTests {
|
|
|
|
|
this.importSelector.setBeanFactory(this.beanFactory); |
|
|
|
|
this.importSelector.setEnvironment(this.environment); |
|
|
|
|
this.importSelector.setResourceLoader(new DefaultResourceLoader()); |
|
|
|
|
this.importSelector.setBeanClassLoader(Thread.currentThread().getContextClassLoader()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
@ -77,7 +85,7 @@ class AutoConfigurationImportSelectorTests {
@@ -77,7 +85,7 @@ class AutoConfigurationImportSelectorTests {
|
|
|
|
|
String[] imports = selectImports(EnableAutoConfigurationWithClassExclusions.class); |
|
|
|
|
assertThat(imports).hasSize(getAutoConfigurationClassNames().size() - 1); |
|
|
|
|
assertThat(this.importSelector.getLastEvent().getExclusions()) |
|
|
|
|
.contains(FreeMarkerAutoConfiguration.class.getName()); |
|
|
|
|
.contains(SeventhAutoConfiguration.class.getName()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
@ -85,7 +93,7 @@ class AutoConfigurationImportSelectorTests {
@@ -85,7 +93,7 @@ class AutoConfigurationImportSelectorTests {
|
|
|
|
|
String[] imports = selectImports(SpringBootApplicationWithClassExclusions.class); |
|
|
|
|
assertThat(imports).hasSize(getAutoConfigurationClassNames().size() - 1); |
|
|
|
|
assertThat(this.importSelector.getLastEvent().getExclusions()) |
|
|
|
|
.contains(FreeMarkerAutoConfiguration.class.getName()); |
|
|
|
|
.contains(SeventhAutoConfiguration.class.getName()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
@ -93,7 +101,7 @@ class AutoConfigurationImportSelectorTests {
@@ -93,7 +101,7 @@ class AutoConfigurationImportSelectorTests {
|
|
|
|
|
String[] imports = selectImports(EnableAutoConfigurationWithClassNameExclusions.class); |
|
|
|
|
assertThat(imports).hasSize(getAutoConfigurationClassNames().size() - 1); |
|
|
|
|
assertThat(this.importSelector.getLastEvent().getExclusions()) |
|
|
|
|
.contains(MustacheAutoConfiguration.class.getName()); |
|
|
|
|
.contains("com.example.one.FirstAutoConfiguration"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
@ -101,36 +109,36 @@ class AutoConfigurationImportSelectorTests {
@@ -101,36 +109,36 @@ class AutoConfigurationImportSelectorTests {
|
|
|
|
|
String[] imports = selectImports(SpringBootApplicationWithClassNameExclusions.class); |
|
|
|
|
assertThat(imports).hasSize(getAutoConfigurationClassNames().size() - 1); |
|
|
|
|
assertThat(this.importSelector.getLastEvent().getExclusions()) |
|
|
|
|
.contains(MustacheAutoConfiguration.class.getName()); |
|
|
|
|
.contains("com.example.three.ThirdAutoConfiguration"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
void propertyExclusionsAreApplied() { |
|
|
|
|
this.environment.setProperty("spring.autoconfigure.exclude", FreeMarkerAutoConfiguration.class.getName()); |
|
|
|
|
this.environment.setProperty("spring.autoconfigure.exclude", "com.example.three.ThirdAutoConfiguration"); |
|
|
|
|
String[] imports = selectImports(BasicEnableAutoConfiguration.class); |
|
|
|
|
assertThat(imports).hasSize(getAutoConfigurationClassNames().size() - 1); |
|
|
|
|
assertThat(this.importSelector.getLastEvent().getExclusions()) |
|
|
|
|
.contains(FreeMarkerAutoConfiguration.class.getName()); |
|
|
|
|
.contains("com.example.three.ThirdAutoConfiguration"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
void severalPropertyExclusionsAreApplied() { |
|
|
|
|
this.environment.setProperty("spring.autoconfigure.exclude", |
|
|
|
|
FreeMarkerAutoConfiguration.class.getName() + "," + MustacheAutoConfiguration.class.getName()); |
|
|
|
|
"com.example.two.SecondAutoConfiguration,com.example.four.FourthAutoConfiguration"); |
|
|
|
|
testSeveralPropertyExclusionsAreApplied(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
void severalPropertyExclusionsAreAppliedWithExtraSpaces() { |
|
|
|
|
this.environment.setProperty("spring.autoconfigure.exclude", |
|
|
|
|
FreeMarkerAutoConfiguration.class.getName() + " , " + MustacheAutoConfiguration.class.getName() + " "); |
|
|
|
|
"com.example.two.SecondAutoConfiguration , com.example.four.FourthAutoConfiguration "); |
|
|
|
|
testSeveralPropertyExclusionsAreApplied(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
void severalPropertyYamlExclusionsAreApplied() { |
|
|
|
|
this.environment.setProperty("spring.autoconfigure.exclude[0]", FreeMarkerAutoConfiguration.class.getName()); |
|
|
|
|
this.environment.setProperty("spring.autoconfigure.exclude[1]", MustacheAutoConfiguration.class.getName()); |
|
|
|
|
this.environment.setProperty("spring.autoconfigure.exclude[0]", "com.example.two.SecondAutoConfiguration"); |
|
|
|
|
this.environment.setProperty("spring.autoconfigure.exclude[1]", "com.example.four.FourthAutoConfiguration"); |
|
|
|
|
testSeveralPropertyExclusionsAreApplied(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -138,17 +146,17 @@ class AutoConfigurationImportSelectorTests {
@@ -138,17 +146,17 @@ class AutoConfigurationImportSelectorTests {
|
|
|
|
|
String[] imports = selectImports(BasicEnableAutoConfiguration.class); |
|
|
|
|
assertThat(imports).hasSize(getAutoConfigurationClassNames().size() - 2); |
|
|
|
|
assertThat(this.importSelector.getLastEvent().getExclusions()) |
|
|
|
|
.contains(FreeMarkerAutoConfiguration.class.getName(), MustacheAutoConfiguration.class.getName()); |
|
|
|
|
.contains("com.example.two.SecondAutoConfiguration", "com.example.four.FourthAutoConfiguration"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
void combinedExclusionsAreApplied() { |
|
|
|
|
this.environment.setProperty("spring.autoconfigure.exclude", ThymeleafAutoConfiguration.class.getName()); |
|
|
|
|
this.environment.setProperty("spring.autoconfigure.exclude", "com.example.one.FirstAutoConfiguration"); |
|
|
|
|
String[] imports = selectImports(EnableAutoConfigurationWithClassAndClassNameExclusions.class); |
|
|
|
|
assertThat(imports).hasSize(getAutoConfigurationClassNames().size() - 3); |
|
|
|
|
assertThat(this.importSelector.getLastEvent().getExclusions()).contains( |
|
|
|
|
FreeMarkerAutoConfiguration.class.getName(), MustacheAutoConfiguration.class.getName(), |
|
|
|
|
ThymeleafAutoConfiguration.class.getName()); |
|
|
|
|
"com.example.one.FirstAutoConfiguration", "com.example.five.FifthAutoConfiguration", |
|
|
|
|
SeventhAutoConfiguration.class.getName()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
@ -213,7 +221,8 @@ class AutoConfigurationImportSelectorTests {
@@ -213,7 +221,8 @@ class AutoConfigurationImportSelectorTests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private List<String> getAutoConfigurationClassNames() { |
|
|
|
|
return ImportCandidates.load(AutoConfiguration.class, getClass().getClassLoader()).getCandidates(); |
|
|
|
|
return ImportCandidates.load(AutoConfiguration.class, Thread.currentThread().getContextClassLoader()) |
|
|
|
|
.getCandidates(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private final class TestAutoConfigurationImportSelector extends AutoConfigurationImportSelector { |
|
|
|
|
@ -278,23 +287,23 @@ class AutoConfigurationImportSelectorTests {
@@ -278,23 +287,23 @@ class AutoConfigurationImportSelectorTests {
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@EnableAutoConfiguration(exclude = FreeMarkerAutoConfiguration.class) |
|
|
|
|
@EnableAutoConfiguration(exclude = SeventhAutoConfiguration.class) |
|
|
|
|
private final class EnableAutoConfigurationWithClassExclusions { |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@SpringBootApplication(exclude = FreeMarkerAutoConfiguration.class) |
|
|
|
|
@SpringBootApplication(exclude = SeventhAutoConfiguration.class) |
|
|
|
|
private final class SpringBootApplicationWithClassExclusions { |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@EnableAutoConfiguration(excludeName = "org.springframework.boot.autoconfigure.mustache.MustacheAutoConfiguration") |
|
|
|
|
@EnableAutoConfiguration(excludeName = "com.example.one.FirstAutoConfiguration") |
|
|
|
|
private final class EnableAutoConfigurationWithClassNameExclusions { |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@EnableAutoConfiguration(exclude = MustacheAutoConfiguration.class, |
|
|
|
|
excludeName = "org.springframework.boot.autoconfigure.freemarker.FreeMarkerAutoConfiguration") |
|
|
|
|
@EnableAutoConfiguration(exclude = SeventhAutoConfiguration.class, |
|
|
|
|
excludeName = "com.example.five.FifthAutoConfiguration") |
|
|
|
|
private final class EnableAutoConfigurationWithClassAndClassNameExclusions { |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
@ -315,9 +324,14 @@ class AutoConfigurationImportSelectorTests {
@@ -315,9 +324,14 @@ class AutoConfigurationImportSelectorTests {
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@SpringBootApplication(excludeName = "org.springframework.boot.autoconfigure.mustache.MustacheAutoConfiguration") |
|
|
|
|
@SpringBootApplication(excludeName = "com.example.three.ThirdAutoConfiguration") |
|
|
|
|
private final class SpringBootApplicationWithClassNameExclusions { |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@AutoConfiguration |
|
|
|
|
static class SeventhAutoConfiguration { |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|