我用@Autowired
注释是这样的:@Autowired注释是否正确使用?
@Autowired
private MyService1 myService1;
@Autowired
private MyService2 myService2;
但是,新的IntelliJ IDE 2016(3)建议,并提出更换:
private final MyService1 myService1;
private final MyService2 myService2;;
@Autowired
public MyClass(MyService1 myService1, MyService2 myService2) {
this.myService1= myService1;
this.myService2= myService2;
}
告诉我有什么区别,什么是正确的?
[Setter DI与Spring中构造函数DI的可能重复?](http://stackoverflow.com/questions/7779509/setter-di-vs-constructor-di-in-spring) – Jesper