@value
@Value("xfy")private String userName;private String userName;@Value("xiao")public void setUserName(String userName) {this.userName = userName;}
@Autowired
// 根据类型进行注入 如果同一类型的Bean有多个,尝试根基名字进行二次匹配 @Autowiredprivate UserDao userDao;public void setUserDao(UserDao userDao) {this.userDao = userDao;}
// 表示@Autowired 使用在方法上不一定要是set方法@Autowiredpublic void cccDao(UserDao userDao) {System.out.println("ccc"+userDao);}
// 将所有的UserDaoBean都注入到List集合中@Autowiredpublic void bbb(List<UserDao> userDaoList){System.out.println("bbb"+userDaoList);}
@Qualifier
// 根据类型进行注入 如果同一类型的Bean有多个,尝试根基名字进行二次匹配
// @Qualifier允许与@Autowired结合使用,使得根据名称注入@Autowired@Qualifier("userDao")private UserDao userDao;public void setUserDao(UserDao userDao) {this.userDao = userDao;}public void show() {System.out.println(userDao);}
@Resource
@Resource(name = "userDao")private UserDao userDao;