Skip to content

Commit 93f77f5

Browse files
committed
Note on multiple @bean methods for same bean
Issue: SPR-13438
1 parent 48576f2 commit 93f77f5

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/asciidoc/core-beans.adoc

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5419,11 +5419,18 @@ factory methods as you see fit in non-`@Configuration` classes and also for stat
54195419
methods anywhere. However, regular `@Bean` methods in `@Configuration` classes need
54205420
to be overridable, i.e. they must not be declared as `private` or `final`.
54215421
5422-
Finally, `@Bean` methods will also be discovered on base classes of a given component
5423-
or configuration class, as well as on Java 8 default methods declared in interfaces
5422+
`@Bean` methods will also be discovered on base classes of a given component or
5423+
configuration class, as well as on Java 8 default methods declared in interfaces
54245424
implemented by the component or configuration class. This allows for a lot of
54255425
flexibility in composing complex configuration arrangements, with even multiple
54265426
inheritance being possible through Java 8 default methods as of Spring 4.2.
5427+
5428+
Finally, note that a single class may hold multiple `@Bean` methods for the same
5429+
bean, as an arrangement of multiple factory methods to use depending on available
5430+
dependencies at runtime. This is the same algorithm as for choosing the "greediest"
5431+
constructor or factory method in other configuration scenarios: The variant with
5432+
the largest number of satisfiable dependencies will be picked at construction time,
5433+
analogous to how the container selects between multiple `@Autowired` constructors.
54275434
====
54285435

54295436

0 commit comments

Comments
 (0)