spring-hibernate-Junit4测试心得

来源:互联网 发布:经济学书籍推荐 知乎 编辑:程序博客网 时间:2024/05/21 05:43

 

在不运行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);

0 0
原创粉丝点击