File tree 2 files changed +14
-1
lines changed
2 files changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -6788,8 +6788,12 @@ work on the configuration class itself since it is being created as a bean insta
6788
6788
@Configuration
6789
6789
public class RepositoryConfig {
6790
6790
6791
+ private final DataSource dataSource;
6792
+
6791
6793
@Autowired
6792
- private DataSource dataSource;
6794
+ public RepositoryConfig(DataSource dataSource) {
6795
+ this.dataSource = dataSource;
6796
+ }
6793
6797
6794
6798
@Bean
6795
6799
public AccountRepository accountRepository() {
@@ -6817,6 +6821,14 @@ work on the configuration class itself since it is being created as a bean insta
6817
6821
}
6818
6822
----
6819
6823
6824
+ [TIP]
6825
+ ====
6826
+ Constructor injection in `@Configuration` classes is only supported as of Spring
6827
+ Framework 4.3. Note also that there is no need to specify `@Autowired` if the target
6828
+ bean defines only one constructor; in the example above, `@Autowired` is not necessary
6829
+ on the `RepositoryConfig` constructor.
6830
+ ====
6831
+
6820
6832
.[[beans-java-injecting-imported-beans-fq]]Fully-qualifying imported beans for ease of navigation
6821
6833
--
6822
6834
In the scenario above, using `@Autowired` works well and provides the desired
Original file line number Diff line number Diff line change @@ -631,6 +631,7 @@ public @interface MyTestConfig {
631
631
632
632
* It is no longer necessary to specify the `@Autowired` annotation if the target
633
633
bean only define one constructor.
634
+ * `@Configuration` classes support constructor injection.
634
635
635
636
636
637
=== Testing Improvements
You can’t perform that action at this time.
0 commit comments