在不运行web程序时 若需要用到junit4测试 需要手动地加载spring的配置文件bean.xml
在获取服务层的bean时需要利用接口来调用
手动获取过程如下:
ApplicationContext context = new FileSystemXmlApplicationContext("classpath:beans.xml");
使用过程如下:
ApplicationContext context = new FileSystemXmlApplicationContext("classpath:beans.xml");
User user = new User("zhangsan", "123345", "123", 0, 0, "123@qq.com");
UserMethodInterf userService = (UserMethodInterf) context.getBean("userServiceBean");
userService.add(user);