what:
--------作用是自动装配bean,而无需再为field设置set,get方法
how:
--------step1 : 在applicationContext.xml中加入扫描@Autowired注解的bean的声明 , 有了这个bean的声明,spring才会去扫描@Autowired注解,@Autowired也才有用。
或者是添加 context:annotation-config/ 或者 context:component-scan/ 标签。
--------step2 : 将加了@Autowired的属性的从目标bean的声明中去掉,不然spring还是会以setter或者contructor的方式去装配bean。
--------step3 : 再要自动装配的field上加注释@Autowired注释,eg :
@Autowired
private TestService testService;
或者是
@Autowired
public setTestService(TestService testService){
this.testService = testService;
}