1616
1717package org .springframework .boot .autoconfigure .condition ;
1818
19+ import org .junit .Ignore ;
1920import org .junit .Test ;
2021import org .springframework .beans .factory .FactoryBean ;
2122import org .springframework .boot .autoconfigure .PropertyPlaceholderAutoConfiguration ;
@@ -109,6 +110,25 @@ public void testAnnotationOnMissingBeanConditionWithEagerFactoryBean() {
109110 assertEquals ("foo" , this .context .getBean ("foo" ));
110111 }
111112
113+ @ Test
114+ @ Ignore ("This will never work - you need to use XML for FactoryBeans, or else call getObject() inside the @Bean method" )
115+ public void testOnMissingBeanConditionWithFactoryBean () {
116+ this .context .register (ExampleBeanAndFactoryBeanConfiguration .class ,
117+ PropertyPlaceholderAutoConfiguration .class );
118+ this .context .refresh ();
119+ // There should be only one
120+ this .context .getBean (ExampleBean .class );
121+ }
122+
123+ @ Test
124+ public void testOnMissingBeanConditionWithFactoryBeanInXml () {
125+ this .context .register (ConfigurationWithFactoryBean .class ,
126+ PropertyPlaceholderAutoConfiguration .class );
127+ this .context .refresh ();
128+ // There should be only one
129+ this .context .getBean (ExampleBean .class );
130+ }
131+
112132 @ Configuration
113133 @ ConditionalOnMissingBean (name = "foo" )
114134 protected static class OnBeanNameConfiguration {
@@ -118,6 +138,21 @@ public String bar() {
118138 }
119139 }
120140
141+ @ Configuration
142+ protected static class ExampleBeanAndFactoryBeanConfiguration {
143+
144+ @ Bean
145+ public FactoryBean <ExampleBean > exampleBeanFactoryBean () {
146+ return new ExampleFactoryBean ("foo" );
147+ }
148+
149+ @ Bean
150+ @ ConditionalOnMissingBean (ExampleBean .class )
151+ public ExampleBean createExampleBean () {
152+ return new ExampleBean ();
153+ }
154+ }
155+
121156 @ Configuration
122157 @ ConditionalOnMissingBean (annotation = EnableScheduling .class )
123158 protected static class OnAnnotationConfiguration {
0 commit comments