Do not further process imports of Object.class
This commit filters out source classes that didn't pass a predicate filter so that they are no longer considered. Closes gh-27080
This commit is contained in:
@@ -91,6 +91,17 @@ public class ImportSelectorTests {
|
||||
ordered.verify(beanFactory).registerBeanDefinition(eq("c"), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void filteredImportSelector() {
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
|
||||
context.register(FilteredConfig.class);
|
||||
context.refresh();
|
||||
String[] beanNames = context.getBeanFactory().getBeanDefinitionNames();
|
||||
assertThat(beanNames).endsWith("importSelectorTests.FilteredConfig",
|
||||
ImportedSelector2.class.getName(), "b");
|
||||
assertThat(beanNames).doesNotContain(Object.class.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
void invokeAwareMethodsInImportSelector() {
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(AwareConfig.class);
|
||||
@@ -274,6 +285,25 @@ public class ImportSelectorTests {
|
||||
}
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@Import(FilteredImportSelector.class)
|
||||
public static class FilteredConfig {
|
||||
}
|
||||
|
||||
public static class FilteredImportSelector implements ImportSelector {
|
||||
|
||||
@Override
|
||||
public String[] selectImports(AnnotationMetadata importingClassMetadata) {
|
||||
return new String[] { ImportedSelector1.class.getName(), ImportedSelector2.class.getName(), ImportedSelector3.class.getName() };
|
||||
}
|
||||
|
||||
@Override
|
||||
public Predicate<String> getExclusionFilter() {
|
||||
return (className -> className.equals(ImportedSelector1.class.getName()) ||
|
||||
className.equals(ImportedSelector3.class.getName()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static class DeferredImportSelector1 implements DeferredImportSelector, Ordered {
|
||||
|
||||
@@ -320,6 +350,15 @@ public class ImportSelectorTests {
|
||||
}
|
||||
}
|
||||
|
||||
@Configuration
|
||||
public static class ImportedSelector3 {
|
||||
|
||||
@Bean
|
||||
public String c() {
|
||||
return "c";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Configuration
|
||||
public static class DeferredImportedSelector1 {
|
||||
|
||||
Reference in New Issue
Block a user