如何理解关于@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 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 我是菜鸟所以不确定是什么他们应该喜欢看。因此,需要一个可重现的示例。