@@ -160,7 +160,7 @@ void testOnMissingBeanConditionOutputShouldNotContainConditionalOnBeanClassInMes
160
160
@ Test
161
161
void testOnMissingBeanConditionWithFactoryBean () {
162
162
this .contextRunner
163
- .withUserConfiguration (FactoryBeanConfiguration .class , ConditionalOnFactoryBean .class ,
163
+ .withUserConfiguration (FactoryBeanConfiguration .class , ConditionalOnMissingBeanProducedByFactoryBean .class ,
164
164
PropertyPlaceholderAutoConfiguration .class )
165
165
.run ((context ) -> assertThat (context .getBean (ExampleBean .class )).hasToString ("fromFactory" ));
166
166
}
@@ -169,73 +169,73 @@ void testOnMissingBeanConditionWithFactoryBean() {
169
169
void testOnMissingBeanConditionWithComponentScannedFactoryBean () {
170
170
this .contextRunner
171
171
.withUserConfiguration (ComponentScannedFactoryBeanBeanMethodConfiguration .class ,
172
- ConditionalOnFactoryBean .class , PropertyPlaceholderAutoConfiguration .class )
172
+ ConditionalOnMissingBeanProducedByFactoryBean .class , PropertyPlaceholderAutoConfiguration .class )
173
173
.run ((context ) -> assertThat (context .getBean (ScanBean .class )).hasToString ("fromFactory" ));
174
174
}
175
175
176
176
@ Test
177
177
void testOnMissingBeanConditionWithComponentScannedFactoryBeanWithBeanMethodArguments () {
178
178
this .contextRunner
179
179
.withUserConfiguration (ComponentScannedFactoryBeanBeanMethodWithArgumentsConfiguration .class ,
180
- ConditionalOnFactoryBean .class , PropertyPlaceholderAutoConfiguration .class )
180
+ ConditionalOnMissingBeanProducedByFactoryBean .class , PropertyPlaceholderAutoConfiguration .class )
181
181
.run ((context ) -> assertThat (context .getBean (ScanBean .class )).hasToString ("fromFactory" ));
182
182
}
183
183
184
184
@ Test
185
185
void testOnMissingBeanConditionWithFactoryBeanWithBeanMethodArguments () {
186
186
this .contextRunner
187
187
.withUserConfiguration (FactoryBeanWithBeanMethodArgumentsConfiguration .class ,
188
- ConditionalOnFactoryBean .class , PropertyPlaceholderAutoConfiguration .class )
188
+ ConditionalOnMissingBeanProducedByFactoryBean .class , PropertyPlaceholderAutoConfiguration .class )
189
189
.withPropertyValues ("theValue=foo" )
190
190
.run ((context ) -> assertThat (context .getBean (ExampleBean .class )).hasToString ("fromFactory" ));
191
191
}
192
192
193
193
@ Test
194
194
void testOnMissingBeanConditionWithConcreteFactoryBean () {
195
195
this .contextRunner
196
- .withUserConfiguration (ConcreteFactoryBeanConfiguration .class , ConditionalOnFactoryBean . class ,
197
- PropertyPlaceholderAutoConfiguration .class )
196
+ .withUserConfiguration (ConcreteFactoryBeanConfiguration .class ,
197
+ ConditionalOnMissingBeanProducedByFactoryBean . class , PropertyPlaceholderAutoConfiguration .class )
198
198
.run ((context ) -> assertThat (context .getBean (ExampleBean .class )).hasToString ("fromFactory" ));
199
199
}
200
200
201
201
@ Test
202
202
void testOnMissingBeanConditionWithUnhelpfulFactoryBean () {
203
203
// We could not tell that the FactoryBean would ultimately create an ExampleBean
204
204
this .contextRunner
205
- .withUserConfiguration (UnhelpfulFactoryBeanConfiguration .class , ConditionalOnFactoryBean . class ,
206
- PropertyPlaceholderAutoConfiguration .class )
205
+ .withUserConfiguration (UnhelpfulFactoryBeanConfiguration .class ,
206
+ ConditionalOnMissingBeanProducedByFactoryBean . class , PropertyPlaceholderAutoConfiguration .class )
207
207
.run ((context ) -> assertThat (context ).getBeans (ExampleBean .class ).hasSize (2 ));
208
208
}
209
209
210
210
@ Test
211
211
void testOnMissingBeanConditionWithRegisteredFactoryBean () {
212
212
this .contextRunner
213
- .withUserConfiguration (RegisteredFactoryBeanConfiguration .class , ConditionalOnFactoryBean . class ,
214
- PropertyPlaceholderAutoConfiguration .class )
213
+ .withUserConfiguration (RegisteredFactoryBeanConfiguration .class ,
214
+ ConditionalOnMissingBeanProducedByFactoryBean . class , PropertyPlaceholderAutoConfiguration .class )
215
215
.run ((context ) -> assertThat (context .getBean (ExampleBean .class )).hasToString ("fromFactory" ));
216
216
}
217
217
218
218
@ Test
219
219
void testOnMissingBeanConditionWithNonspecificFactoryBeanWithClassAttribute () {
220
220
this .contextRunner
221
221
.withUserConfiguration (NonspecificFactoryBeanClassAttributeConfiguration .class ,
222
- ConditionalOnFactoryBean .class , PropertyPlaceholderAutoConfiguration .class )
222
+ ConditionalOnMissingBeanProducedByFactoryBean .class , PropertyPlaceholderAutoConfiguration .class )
223
223
.run ((context ) -> assertThat (context .getBean (ExampleBean .class )).hasToString ("fromFactory" ));
224
224
}
225
225
226
226
@ Test
227
227
void testOnMissingBeanConditionWithNonspecificFactoryBeanWithStringAttribute () {
228
228
this .contextRunner
229
229
.withUserConfiguration (NonspecificFactoryBeanStringAttributeConfiguration .class ,
230
- ConditionalOnFactoryBean .class , PropertyPlaceholderAutoConfiguration .class )
230
+ ConditionalOnMissingBeanProducedByFactoryBean .class , PropertyPlaceholderAutoConfiguration .class )
231
231
.run ((context ) -> assertThat (context .getBean (ExampleBean .class )).hasToString ("fromFactory" ));
232
232
}
233
233
234
234
@ Test
235
235
void testOnMissingBeanConditionWithFactoryBeanInXml () {
236
236
this .contextRunner
237
- .withUserConfiguration (FactoryBeanXmlConfiguration .class , ConditionalOnFactoryBean . class ,
238
- PropertyPlaceholderAutoConfiguration .class )
237
+ .withUserConfiguration (FactoryBeanXmlConfiguration .class ,
238
+ ConditionalOnMissingBeanProducedByFactoryBean . class , PropertyPlaceholderAutoConfiguration .class )
239
239
.run ((context ) -> assertThat (context .getBean (ExampleBean .class )).hasToString ("fromFactory" ));
240
240
}
241
241
@@ -377,6 +377,15 @@ void typeBasedMatchingIgnoresBeanThatIsNotDefaultCandidate() {
377
377
.run ((context ) -> assertThat (context ).hasBean ("bar" ));
378
378
}
379
379
380
+ @ Test
381
+ void typeBasedMatchingIgnoresFactoryBeanThatIsNotDefaultCandidate () {
382
+ this .contextRunner
383
+ .withUserConfiguration (NotDefaultCandidateFactoryBeanConfiguration .class ,
384
+ ConditionalOnMissingFactoryBean .class )
385
+ .run ((context ) -> assertThat (context ).hasBean ("&exampleFactoryBean" )
386
+ .hasBean ("&additionalExampleFactoryBean" ));
387
+ }
388
+
380
389
@ Test
381
390
void nameBasedMatchingConsidersBeanThatIsNotDefaultCandidate () {
382
391
this .contextRunner .withUserConfiguration (NotDefaultCandidateConfig .class , OnBeanNameConfiguration .class )
@@ -447,7 +456,17 @@ String bar() {
447
456
static class FactoryBeanConfiguration {
448
457
449
458
@ Bean
450
- FactoryBean <ExampleBean > exampleBeanFactoryBean () {
459
+ ExampleFactoryBean exampleBeanFactoryBean () {
460
+ return new ExampleFactoryBean ("foo" );
461
+ }
462
+
463
+ }
464
+
465
+ @ Configuration (proxyBeanMethods = false )
466
+ static class NotDefaultCandidateFactoryBeanConfiguration {
467
+
468
+ @ Bean (defaultCandidate = false )
469
+ ExampleFactoryBean exampleFactoryBean () {
451
470
return new ExampleFactoryBean ("foo" );
452
471
}
453
472
@@ -548,7 +567,7 @@ static class FactoryBeanXmlConfiguration {
548
567
}
549
568
550
569
@ Configuration (proxyBeanMethods = false )
551
- static class ConditionalOnFactoryBean {
570
+ static class ConditionalOnMissingBeanProducedByFactoryBean {
552
571
553
572
@ Bean
554
573
@ ConditionalOnMissingBean
@@ -558,6 +577,17 @@ ExampleBean createExampleBean() {
558
577
559
578
}
560
579
580
+ @ Configuration (proxyBeanMethods = false )
581
+ static class ConditionalOnMissingFactoryBean {
582
+
583
+ @ Bean
584
+ @ ConditionalOnMissingBean
585
+ ExampleFactoryBean additionalExampleFactoryBean () {
586
+ return new ExampleFactoryBean ("factory" );
587
+ }
588
+
589
+ }
590
+
561
591
@ Configuration (proxyBeanMethods = false )
562
592
static class ConditionalOnIgnoredSubclass {
563
593
0 commit comments