Skip to content

Commit 767299c

Browse files
Thomas Darimontsnicoll
andcommitted
Document @bean definitions via default methods
See gh-767 Co-authored-by: Stephane Nicoll <[email protected]>
1 parent 3290495 commit 767299c

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/docs/asciidoc/core/core-beans.adoc

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7953,6 +7953,26 @@ following text image shows:
79537953
transferService -> com.acme.TransferServiceImpl
79547954
----
79557955

7956+
You can also use default methods to define beans. This allows composition of bean
7957+
configurations by implementing interfaces with bean definitions on default methods.
7958+
7959+
[source,java,indent=0,subs="verbatim,quotes",role="primary"]
7960+
.Java
7961+
----
7962+
public interface BaseConfig {
7963+
7964+
@Bean
7965+
default TransferServiceImpl transferService() {
7966+
return new TransferServiceImpl();
7967+
}
7968+
}
7969+
7970+
@Configuration
7971+
public class AppConfig implements BaseConfig {
7972+
7973+
}
7974+
----
7975+
79567976
You can also declare your `@Bean` method with an interface (or base class)
79577977
return type, as the following example shows:
79587978

0 commit comments

Comments
 (0)