Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于对象注入的问题 #5

Open
GongXincheng opened this issue Oct 9, 2019 · 7 comments
Open

关于对象注入的问题 #5

GongXincheng opened this issue Oct 9, 2019 · 7 comments
Labels
enhancement New feature or request

Comments

@GongXincheng
Copy link

我看了代码 都是使用的构造方式注入,为什么不用@resource或者@Autowired 注解式注入呢? 是有什么说法吗?

@douzeping
Copy link
Contributor

个人理解,对写测试比较友好

@GongXincheng
Copy link
Author

个人理解,对写测试比较友好

好的 谢谢

@Snailclimb
Copy link
Owner

我看了代码 都是使用的构造方式注入,为什么不用@resource或者@Autowired 注解式注入呢? 是有什么说法吗?

工程实践推荐使用的就是构造方法注入哦!具体原因我忘了。

@GongXincheng
Copy link
Author

我看了代码 都是使用的构造方式注入,为什么不用@resource或者@Autowired 注解式注入呢? 是有什么说法吗?

工程实践推荐使用的就是构造方法注入哦!具体原因我忘了。

好的 学习啦 🤝

@Snailclimb Snailclimb added the enhancement New feature or request label Oct 15, 2019
@richardplas
Copy link

我看了代码 都是使用的构造方式注入,为什么不用@resource或者@Autowired 注解式注入呢? 是有什么说法吗?

工程实践推荐使用的就是构造方法注入哦!具体原因我忘了。

构造器注入解决不了循环依赖的问题吧。

@douzeping
Copy link
Contributor

我看了代码 都是使用的构造方式注入,为什么不用@resource或者@Autowired 注解式注入呢? 是有什么说法吗?

工程实践推荐使用的就是构造方法注入哦!具体原因我忘了。

构造器注入解决不了循环依赖的问题吧。

那就可以考虑用setter吧,毕竟直接@Autowired会有warning,虽然我们公司都是@Autowired一把梭

@yukiloh
Copy link

yukiloh commented Nov 30, 2019

事实上idea(我是19.1)可以对autowired自动转换位构造器,直接alt + enter就完事了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants