From 1af052433cdf87e00a558d7cf5c76828476b421e Mon Sep 17 00:00:00 2001 From: sdeleuze Date: Tue, 23 Jan 2018 18:02:25 +0100 Subject: [PATCH] Document @Bean nullable parameters optional bean injection Issue: SPR-16053 --- src/docs/asciidoc/languages/kotlin.adoc | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/docs/asciidoc/languages/kotlin.adoc b/src/docs/asciidoc/languages/kotlin.adoc index bdc9450e860..2f73849977a 100644 --- a/src/docs/asciidoc/languages/kotlin.adoc +++ b/src/docs/asciidoc/languages/kotlin.adoc @@ -149,11 +149,17 @@ define the `required` attribute. That means `@RequestParam name: String?` will as not required and conversely `@RequestParam name: String` as being required. This feature is also supported on the Spring Messaging `@Header` annotation. -In a similar fashion, Spring bean injection with `@Autowired` or `@Inject` uses this information -to determine if a bean is required or not. `@Autowired lateinit var foo: Foo` implies that a bean -of type `Foo` must be registered in the application context while `@Autowired lateinit var foo: Foo?` +In a similar fashion, Spring bean injection with `@Autowired`, `@Bean` or `@Inject` uses +this information to determine if a bean is required or not. + +For example, `@Autowired lateinit var foo: Foo` implies that a bean +of type `Foo` must be registered in the application context, while `@Autowired lateinit var foo: Foo?` won’t raise an error if such bean does not exist. +Following the same principle, `@Bean fun baz(foo: Foo, bar: Bar?) = Baz(foo, bar)` implies +that a bean of type `Foo` must be registered in the application context while a bean of +type `Bar` may or may not exist. The same behavior applies to autowired constructor parameters. + [NOTE] ==== If you are using bean validation on classes with