Skip to content

Commit d32d65b

Browse files
committed
Add tip about providing as much typo info as possible in @bean methods
Closes gh-22925
1 parent e7eb773 commit d32d65b

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7427,6 +7427,10 @@ For this reason, we recommend using only `@ConditionalOnBean` and `@ConditionalO
74277427
NOTE: `@ConditionalOnBean` and `@ConditionalOnMissingBean` do not prevent `@Configuration` classes from being created.
74287428
The only difference between using these conditions at the class level and marking each contained `@Bean` method with the annotation is that the former prevents registration of the `@Configuration` class as a bean if the condition does not match.
74297429

7430+
TIP: When declaring a `@Bean` method, provide as much type information as possible in the method's return type.
7431+
For example, if your bean's concrete class implements an interface the bean method's return type should be the concrete class and not the interface.
7432+
Providing as much type information as possible in `@Bean` methods is particularly important when using bean conditions as their evaluation can only rely upon to type information that's available in the method signature.
7433+
74307434

74317435

74327436
[[boot-features-property-conditions]]

0 commit comments

Comments
 (0)