Skip to content

Commit

Permalink
Add tip about providing as much typo info as possible in @bean methods
Browse files Browse the repository at this point in the history
Closes gh-22925
  • Loading branch information
wilkinsona committed Nov 3, 2020
1 parent e7eb773 commit d32d65b
Showing 1 changed file with 4 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7427,6 +7427,10 @@ For this reason, we recommend using only `@ConditionalOnBean` and `@ConditionalO
NOTE: `@ConditionalOnBean` and `@ConditionalOnMissingBean` do not prevent `@Configuration` classes from being created.
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.

TIP: When declaring a `@Bean` method, provide as much type information as possible in the method's return type.
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.
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.



[[boot-features-property-conditions]]
Expand Down

0 comments on commit d32d65b

Please sign in to comment.