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"/>

posted on 2016-08-24 23:59  _故乡的原风景  阅读(109)  评论(0编辑  收藏  举报