@@ -234,6 +234,10 @@ For details about the mechanism for supplying arguments to the constructor (if r
234
234
and setting object instance properties after the object is constructed, see
235
235
xref:core/beans/dependencies/factory-collaborators.adoc[Injecting Dependencies].
236
236
237
+ NOTE: In the case of constructor arguments, the container can select a corresponding
238
+ constructor among several overloaded constructors. That said, to avoid ambiguities,
239
+ it is recommended to keep your constructor signatures as straightforward as possible.
240
+
237
241
238
242
[[beans-factory-class-static-factory-method]]
239
243
=== Instantiation with a Static Factory Method
@@ -294,6 +298,24 @@ For details about the mechanism for supplying (optional) arguments to the factor
294
298
and setting object instance properties after the object is returned from the factory,
295
299
see xref:core/beans/dependencies/factory-properties-detailed.adoc[Dependencies and Configuration in Detail].
296
300
301
+ NOTE: In the case of factory method arguments, the container can select a corresponding
302
+ method among several overloaded methods of the same name. That said, to avoid ambiguities,
303
+ it is recommended to keep your factory method signatures as straightforward as possible.
304
+
305
+ [TIP]
306
+ ====
307
+ A typical problematic case with factory method overloading is Mockito with its many
308
+ overloads of the `mock` method. Choose the most specific variant of `mock` possible:
309
+
310
+ [source,xml,indent=0,subs="verbatim,quotes"]
311
+ ----
312
+ <bean id="clientService" class="org.mockito.Mockito" factory-method="mock">
313
+ <constructor-arg type="java.lang.Class" value="examples.ClientService"/>
314
+ <constructor-arg type="java.lang.String" value="clientService"/>
315
+ </bean>
316
+ ----
317
+ ====
318
+
297
319
298
320
[[beans-factory-class-instance-factory-method]]
299
321
=== Instantiation by Using an Instance Factory Method
@@ -416,8 +438,8 @@ Kotlin::
416
438
======
417
439
418
440
This approach shows that the factory bean itself can be managed and configured through
419
- dependency injection (DI). See xref:core/beans/dependencies/factory-properties-detailed.adoc[Dependencies and Configuration in Detail]
420
- .
441
+ dependency injection (DI).
442
+ See xref:core/beans/dependencies/factory-properties-detailed.adoc[Dependencies and Configuration in Detail] .
421
443
422
444
NOTE: In Spring documentation, "factory bean" refers to a bean that is configured in the
423
445
Spring container and that creates objects through an
@@ -444,5 +466,3 @@ cases into account and returns the type of object that a `BeanFactory.getBean` c
444
466
going to return for the same bean name.
445
467
446
468
447
-
448
-
0 commit comments