|
|
|
|
@ -36,10 +36,8 @@ import org.springframework.beans.factory.BeanFactory;
@@ -36,10 +36,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.context.annotation.DeferredImportSelector.Group; |
|
|
|
|
import org.springframework.context.annotation.DeferredImportSelector.Group.Entry; |
|
|
|
|
@ -57,6 +55,15 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
@@ -57,6 +55,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(null); |
|
|
|
|
@ -84,7 +91,7 @@ class AutoConfigurationImportSelectorTests {
@@ -84,7 +91,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 |
|
|
|
|
@ -92,7 +99,7 @@ class AutoConfigurationImportSelectorTests {
@@ -92,7 +99,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 |
|
|
|
|
@ -100,7 +107,7 @@ class AutoConfigurationImportSelectorTests {
@@ -100,7 +107,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 |
|
|
|
|
@ -108,36 +115,36 @@ class AutoConfigurationImportSelectorTests {
@@ -108,36 +115,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(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -145,17 +152,17 @@ class AutoConfigurationImportSelectorTests {
@@ -145,17 +152,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 |
|
|
|
|
@ -247,13 +254,15 @@ class AutoConfigurationImportSelectorTests {
@@ -247,13 +254,15 @@ class AutoConfigurationImportSelectorTests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private List<String> getAutoConfigurationClassNames() { |
|
|
|
|
return ImportCandidates.load(AutoConfiguration.class, getClass().getClassLoader()).getCandidates(); |
|
|
|
|
return ImportCandidates.load(AutoConfiguration.class, Thread.currentThread().getContextClassLoader()) |
|
|
|
|
.getCandidates(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void setupImportSelector(TestAutoConfigurationImportSelector importSelector) { |
|
|
|
|
importSelector.setBeanFactory(this.beanFactory); |
|
|
|
|
importSelector.setEnvironment(this.environment); |
|
|
|
|
importSelector.setResourceLoader(new DefaultResourceLoader()); |
|
|
|
|
importSelector.setBeanClassLoader(Thread.currentThread().getContextClassLoader()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private final class TestAutoConfigurationImportSelector extends AutoConfigurationImportSelector { |
|
|
|
|
@ -322,23 +331,23 @@ class AutoConfigurationImportSelectorTests {
@@ -322,23 +331,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 { |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
@ -359,7 +368,7 @@ class AutoConfigurationImportSelectorTests {
@@ -359,7 +368,7 @@ class AutoConfigurationImportSelectorTests {
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@SpringBootApplication(excludeName = "org.springframework.boot.autoconfigure.mustache.MustacheAutoConfiguration") |
|
|
|
|
@SpringBootApplication(excludeName = "com.example.three.ThirdAutoConfiguration") |
|
|
|
|
private final class SpringBootApplicationWithClassNameExclusions { |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
@ -383,4 +392,9 @@ class AutoConfigurationImportSelectorTests {
@@ -383,4 +392,9 @@ class AutoConfigurationImportSelectorTests {
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@AutoConfiguration |
|
|
|
|
static class SeventhAutoConfiguration { |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|