您的位置:首页 > 编程语言 > Java开发

spring-hibernate-Junit4测试心得

2016-04-13 21:15 387 查看
在不运行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);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: