From 1fc3fc8bf7469169b6eed0bf7d03b263e005ad44 Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Mon, 21 Dec 2015 14:47:50 +0100 Subject: [PATCH] Update documentation Issue: SPR-13471 --- src/asciidoc/core-beans.adoc | 14 +++++++++++++- src/asciidoc/whats-new.adoc | 1 + 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/asciidoc/core-beans.adoc b/src/asciidoc/core-beans.adoc index 8c505c4d38..723d482a76 100644 --- a/src/asciidoc/core-beans.adoc +++ b/src/asciidoc/core-beans.adoc @@ -6788,8 +6788,12 @@ work on the configuration class itself since it is being created as a bean insta @Configuration public class RepositoryConfig { + private final DataSource dataSource; + @Autowired - private DataSource dataSource; + public RepositoryConfig(DataSource dataSource) { + this.dataSource = dataSource; + } @Bean public AccountRepository accountRepository() { @@ -6817,6 +6821,14 @@ work on the configuration class itself since it is being created as a bean insta } ---- +[TIP] +==== +Constructor injection in `@Configuration` classes is only supported as of Spring +Framework 4.3. Note also that there is no need to specify `@Autowired` if the target +bean defines only one constructor; in the example above, `@Autowired` is not necessary +on the `RepositoryConfig` constructor. +==== + .[[beans-java-injecting-imported-beans-fq]]Fully-qualifying imported beans for ease of navigation -- In the scenario above, using `@Autowired` works well and provides the desired diff --git a/src/asciidoc/whats-new.adoc b/src/asciidoc/whats-new.adoc index ff1a2a0362..89100e4c8d 100644 --- a/src/asciidoc/whats-new.adoc +++ b/src/asciidoc/whats-new.adoc @@ -631,6 +631,7 @@ public @interface MyTestConfig { * It is no longer necessary to specify the `@Autowired` annotation if the target bean only define one constructor. +* `@Configuration` classes support constructor injection. === Testing Improvements -- GitLab