Skip to content

Commit

Permalink
Document @bean definitions via default methods
Browse files Browse the repository at this point in the history
See gh-767

Co-authored-by: Stephane Nicoll <snicoll@vmware.com>
  • Loading branch information
Thomas Darimont and snicoll committed Nov 22, 2021
1 parent 3290495 commit 767299c
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/docs/asciidoc/core/core-beans.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -7953,6 +7953,26 @@ following text image shows:
transferService -> com.acme.TransferServiceImpl
----

You can also use default methods to define beans. This allows composition of bean
configurations by implementing interfaces with bean definitions on default methods.

[source,java,indent=0,subs="verbatim,quotes",role="primary"]
.Java
----
public interface BaseConfig {
@Bean
default TransferServiceImpl transferService() {
return new TransferServiceImpl();
}
}
@Configuration
public class AppConfig implements BaseConfig {
}
----

You can also declare your `@Bean` method with an interface (or base class)
return type, as the following example shows:

Expand Down

0 comments on commit 767299c

Please sign in to comment.