16
16
17
17
package org .springframework .boot .autoconfigure .condition ;
18
18
19
+ import org .junit .Ignore ;
19
20
import org .junit .Test ;
20
21
import org .springframework .beans .factory .FactoryBean ;
21
22
import org .springframework .boot .autoconfigure .PropertyPlaceholderAutoConfiguration ;
@@ -109,6 +110,25 @@ public void testAnnotationOnMissingBeanConditionWithEagerFactoryBean() {
109
110
assertEquals ("foo" , this .context .getBean ("foo" ));
110
111
}
111
112
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
+
112
132
@ Configuration
113
133
@ ConditionalOnMissingBean (name = "foo" )
114
134
protected static class OnBeanNameConfiguration {
@@ -118,6 +138,21 @@ public String bar() {
118
138
}
119
139
}
120
140
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
+
121
156
@ Configuration
122
157
@ ConditionalOnMissingBean (annotation = EnableScheduling .class )
123
158
protected static class OnAnnotationConfiguration {
0 commit comments