如何理解关于@Autowired 的 spring 参考文档

How to understand the spring reference documentation regarding @Autowired

希望这个问题足够简单。我正在阅读 Spring Framework Reference:beans-java 部分,我遇到了这个用法示例

让我困惑的部分是最后的注释,特别是它说的地方

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.

我不太明白为什么我可以从RepositoryConfig()中删除@Autowired?在这种情况下,目标 bean 是什么?它们指的是什么构造函数?

我试图重现这个,但文档没有提供 AccountRepository class 或 TransferService class 我是菜鸟所以不确定是什么他们应该喜欢看。因此,需要一个可重现的示例。

Spring 4.3 之前的版本要求您使用 @Autowired 注释要使用的构造函数。即使你的 class 只有一个构造函数。

从 Spring 4.3 开始,当您的 class 有一个构造函数时,您可以在构造函数中省略 @Autowired,因为 Spring 然后会自动假设您要使用那个构造函数。

查看 this blog for more information and here Jira 票证。