spring注解注入
@Autowired
public void setUserDAO(UserDAO userDAO) {this.userDAO = userDAO;
}
@Test
public void test1() {
ClassPathXmlApplicationContext app = new ClassPathXmlApplicationContext("applicationContext.xml");
UserService service = (UserService)app.getBean("userService");//所有对象通过spring方式获取
service.saveUser();
}
<bean name="userService" class="com.ioc.service.UserService"/>
邮箱:wangh_2@sina.com