Add String type attribute to OnBean conditions
Fixes gh-1381
This commit is contained in:
@@ -76,6 +76,14 @@ public class ConditionalOnBeanTests {
|
||||
assertEquals("bar", this.context.getBean("bar"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClassOnBeanClassNameCondition() {
|
||||
this.context.register(FooConfiguration.class, OnBeanClassNameConfiguration.class);
|
||||
this.context.refresh();
|
||||
assertTrue(this.context.containsBean("bar"));
|
||||
assertEquals("bar", this.context.getBean("bar"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnBeanConditionWithXml() {
|
||||
this.context.register(XmlConfiguration.class, OnBeanNameConfiguration.class);
|
||||
@@ -100,6 +108,14 @@ public class ConditionalOnBeanTests {
|
||||
assertEquals("bar", this.context.getBean("bar"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnMissingBeanType() throws Exception {
|
||||
this.context.register(FooConfiguration.class,
|
||||
OnBeanMissingClassConfiguration.class);
|
||||
this.context.refresh();
|
||||
assertFalse(this.context.containsBean("bar"));
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@ConditionalOnBean(name = "foo")
|
||||
protected static class OnBeanNameConfiguration {
|
||||
@@ -136,6 +152,24 @@ public class ConditionalOnBeanTests {
|
||||
}
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@ConditionalOnBean(type = "java.lang.String")
|
||||
protected static class OnBeanClassNameConfiguration {
|
||||
@Bean
|
||||
public String bar() {
|
||||
return "bar";
|
||||
}
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@ConditionalOnBean(type = "some.type.Missing")
|
||||
protected static class OnBeanMissingClassConfiguration {
|
||||
@Bean
|
||||
public String bar() {
|
||||
return "bar";
|
||||
}
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@EnableScheduling
|
||||
protected static class FooConfiguration {
|
||||
|
||||
Reference in New Issue
Block a user