Ensure @Conditions consider super classes
Fix @Condition evaluation to also consider super classes for both @Configuration classes and regular @Components. This change allows @Conditional annotations to be inherited and restores the previous behavior of @Profile. Issue: SPR-10840
This commit is contained in:
@@ -54,6 +54,21 @@ public class ConfigurationClassWithConditionTests {
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void conditionalOnConfiguration() throws Exception {
|
||||
ctx.register(ConditionOnConfiguration.class);
|
||||
ctx.refresh();
|
||||
assertThat(ctx.getBeansOfType(ConditionOnConfiguration.class).size(), equalTo(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void inheritedConditionalOnConfiguration() throws Exception {
|
||||
ctx.register(InheritedConditionOnConfiguration.class);
|
||||
ctx.refresh();
|
||||
assertThat(ctx.getBeansOfType(ConditionOnConfiguration.class).size(), equalTo(0));
|
||||
assertThat(ctx.getBeansOfType(InheritedConditionOnConfiguration.class).size(), equalTo(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void conditionalOnMissingBeanMatch() throws Exception {
|
||||
ctx.register(BeanOneConfiguration.class, BeanTwoConfiguration.class);
|
||||
@@ -103,6 +118,14 @@ public class ConfigurationClassWithConditionTests {
|
||||
assertNull(ctx.getBean(NonConfigurationClass.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void inheritedNonConfigurationClass() throws Exception {
|
||||
ctx.register(InheritedNonConfigurationClass.class);
|
||||
ctx.refresh();
|
||||
thrown.expect(NoSuchBeanDefinitionException.class);
|
||||
assertNull(ctx.getBean(InheritedNonConfigurationClass.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void methodConditional() throws Exception {
|
||||
ctx.register(ConditionOnMethodConfiguration.class);
|
||||
@@ -118,6 +141,13 @@ public class ConfigurationClassWithConditionTests {
|
||||
ctx.refresh();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void inheritedImportsNotCreated() throws Exception {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.register(InheritedImportsNotCreated.class);
|
||||
ctx.refresh();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void importsNotLoaded() throws Exception {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
@@ -228,6 +258,10 @@ public class ConfigurationClassWithConditionTests {
|
||||
static class NonConfigurationClass {
|
||||
}
|
||||
|
||||
@Component
|
||||
static class InheritedNonConfigurationClass extends NonConfigurationClass {
|
||||
}
|
||||
|
||||
@Configuration
|
||||
static class ConditionOnMethodConfiguration {
|
||||
|
||||
@@ -247,6 +281,21 @@ public class ConfigurationClassWithConditionTests {
|
||||
}
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@Never
|
||||
static class ConditionOnConfiguration {
|
||||
}
|
||||
|
||||
@Configuration
|
||||
static class InheritedConditionOnConfiguration extends ConditionOnConfiguration {
|
||||
}
|
||||
|
||||
|
||||
@Import({ ConfigurationNotCreated.class, RegistrarNotCreated.class, ImportSelectorNotCreated.class })
|
||||
static class InheritedImportsNotCreated extends ConditionOnConfiguration {
|
||||
|
||||
}
|
||||
|
||||
@Configuration
|
||||
static class ConfigurationNotCreated {
|
||||
static {
|
||||
|
||||
Reference in New Issue
Block a user