spring-知识小结之注解为属性赋值
<1>.本类中的属性赋值
public class UserServiceImpl implements UserService { //按照类别赋值 // @Autowired //按照名称赋值 // @Autowired // @Qualifier("userDao") //按照名字赋值 @Resource private UserDao userDao; public void setUserDao(UserDao userDao) { this.userDao = userDao; } }
<2>.为父类属性赋值
public class UserDaoImpl extends HibernateDaoSupport implements UserDao { /* sessionFactory的get,set方法在父类中为final,不可重写 */ @Autowired public void setMySessionFactory(SessionFactory sessionFactory) { super.setSessionFactory(sessionFactory); } }