提交 1fc3fc8b 编写于 作者: S Stephane Nicoll

Update documentation

Issue: SPR-13471
上级 edd8e2d5
...@@ -6788,8 +6788,12 @@ work on the configuration class itself since it is being created as a bean insta ...@@ -6788,8 +6788,12 @@ work on the configuration class itself since it is being created as a bean insta
@Configuration @Configuration
public class RepositoryConfig { public class RepositoryConfig {
private final DataSource dataSource;
@Autowired @Autowired
private DataSource dataSource; public RepositoryConfig(DataSource dataSource) {
this.dataSource = dataSource;
}
@Bean @Bean
public AccountRepository accountRepository() { public AccountRepository accountRepository() {
...@@ -6817,6 +6821,14 @@ work on the configuration class itself since it is being created as a bean insta ...@@ -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 .[[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 In the scenario above, using `@Autowired` works well and provides the desired
......
...@@ -631,6 +631,7 @@ public @interface MyTestConfig { ...@@ -631,6 +631,7 @@ public @interface MyTestConfig {
* It is no longer necessary to specify the `@Autowired` annotation if the target * It is no longer necessary to specify the `@Autowired` annotation if the target
bean only define one constructor. bean only define one constructor.
* `@Configuration` classes support constructor injection.
=== Testing Improvements === Testing Improvements
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册