1 2 3 4 下一页 1.1. 使用注解以前我们是怎样注入属性的 类的实现: public class UserManagerImpl implements UserManager { private UserDao userDao; public void setUserDao(UserDao userDao) { this.userDao = userDao; } ... }
配置文件: < bean id="userManagerImpl" class="com.kedacom.spring.annotation.service.UserManagerImpl"> < property name="userDao" ref="userDao" /> < /bean> < bean id="userDao" class="com.kedacom.spring.annotation.persistence.UserDaoImpl"> < property name="sessionFactory" ref="mySessionFactory" /> < /bean>
1.2. 引入@Autowired注解(不推荐使用,建议使用@Resource) 类的实现(对成员变量进行标注) public class UserManagerImpl implements UserManager { @Autowired private UserDao userDao; ... }
或者(对方法进行标注) public class UserManagerImpl implements UserManager { private UserDao userDao; @Autowired public void setUserDao(UserDao userDao) { this.userDao = userDao; } ... }
(责任编辑:admin) |