Hibernate整合Spring,没有展现层进行手动测试
2013-11-20 13:42
218 查看
一般的开发是SSH整合后,进行简单的测试,也就是说在Web服务器环境下进行测试,因为对于Spring的加载都配置在了web.xml文件中,如下:
这时的测试数据就必须从页面传递过来,如果离开页面,也就是不依靠Tomcat服务器来加载,我们可以自己加载关于spring配置文件ApplicationContext.xml文件.现在总结一下有几种情况来加载ApplicationContext.xml文件:
现以第一种方式为例:
@Test
public void TestMethod()
{
AbstractApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");//手动加载spring配置文件
UserService userSerivce = (UserService) context.getBean("userService");//从context容器对象中取得名为userService的对象("userService"为配置文件中某个bean的id)
User user = new User();
user.setUserId("002");
user.setUserName("admin1");
user.setPassword("12341");
user.setStatus(new BigDecimal(1));
Role role1 = new Role();
role1.setRoleId("role001");
role1.setRoleName("系统管理员1");
System.out.println("执行到最后31");
userSerivce.addUser(user);
//userDaoImpl.save(user);
context.close();
}
这时的测试数据就必须从页面传递过来,如果离开页面,也就是不依靠Tomcat服务器来加载,我们可以自己加载关于spring配置文件ApplicationContext.xml文件.现在总结一下有几种情况来加载ApplicationContext.xml文件:
现以第一种方式为例:
@Test
public void TestMethod()
{
AbstractApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");//手动加载spring配置文件
UserService userSerivce = (UserService) context.getBean("userService");//从context容器对象中取得名为userService的对象("userService"为配置文件中某个bean的id)
User user = new User();
user.setUserId("002");
user.setUserName("admin1");
user.setPassword("12341");
user.setStatus(new BigDecimal(1));
Role role1 = new Role();
role1.setRoleId("role001");
role1.setRoleName("系统管理员1");
System.out.println("执行到最后31");
userSerivce.addUser(user);
//userDaoImpl.save(user);
context.close();
}
相关文章推荐
- Spring+Hibernate进行双数据源测试Mysql集群读写分离
- 使用注解方式进行spring和hibernate整合
- 使用struts、hibernate、spring进行框架整合流程详细说明(完整版)附:开发规范
- 使用struts、hibernate、spring进行框架整合流程详细说明
- 【JavaWeb-25】事务管理相关知识、手动/半自动/自动管理事务案例、整合Junit、整合Web、spring和hibernate整合、struts2和spring整合
- Struts2_Spring_Hibernate整合及测试_3(标准)
- Spring整合hibernate:3、使用XML进行声明式的事务管理
- Spring 集成Hibernate 并进行测试
- Struts2_Spring_Hibernate整合及测试_1(标准)
- 手动配置三大框架整合,Spring+Struts2+Hibernate
- Spring整合Hibernate后没有自动在数据库中创建表结构
- 使用struts、hibernate、spring进行框架整合流程详细说明(完整版)
- Junit和spring整合,使用Spring托管对象进行依赖注入,方便测试
- SSH网站开发实录(3)测试整合的SSH框架是否能用 SpringMVC+Spring+Hibernate
- spring和hibernate整合后手动管理事务工具类
- 使用struts、hibernate、spring进行框架整合流程详细说明
- 关于spring整合hibernate使用update无异常但没有效果(不输出sql语句)
- 在Struts+Spring+hibernate中,将FormBean与EntityBean进行整合
- spring+hibernate整合,不能启动spring容器进行单元测试
- Spring整合Hibernate:2、使用Annotation方式进行声明式的事务管理