第一种:属性注入
1、编写 com.gx.model.Car (用于依赖对象的演示), com.gx.model.PersonSetter :
2. 在applicationContext.xml中配置:
3. 编写测试方法:
第二种:构造器注入
- 编写 com.gx.model.PersonConstructor 类:
- 在applicationContext.xml中配置:
3、编写测试方法:
第三种:使用注解方式注入
1、编写IUserDao接口和对应的实现类UserDaoImpl:
2、编写IUserService接口和对应的实现类UserServiceImpl:
3、配置applicationContext.xml:
4、编写测试方法:
第四种:使用全注解方式注入
1.在类UserDaoImpl上添加@Repository注解:
2、在类UserServiceImpl上添加@Service的注解:
3.配置applicationContext.xml:
4.编写测试类 TestFiledAnnotation: