From d32d65b02cd3d0a3d0ca5890c42de40630cd16c1 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Tue, 3 Nov 2020 10:16:20 +0000 Subject: [PATCH] Add tip about providing as much typo info as possible in @Bean methods Closes gh-22925 --- .../src/main/asciidoc/spring-boot-features.adoc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc b/spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc index d745b5d70ad9..b4f5ffd03380 100644 --- a/spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc +++ b/spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc @@ -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]]