spring依赖注入的三种方式

  • 变量(filed) 注入
@Autowired
 UserDao userDao;
  • 构造器注入
final UserDao userDao;
@Autowired
public UserServiceImpl(UserDao userDao){
        this.userDao = userDao;
}
  • set 方法注入
private UserDao userDao;
@Autowired
public void setUserDao(UserDao userDao){
        this.userDao = userDao;
}
  • 这三种方式的区别


来自为知笔记(Wiz)


posted on 2020-08-11 01:07  白衣风云  阅读(222)  评论(0编辑  收藏  举报

导航