mybatis +junit4 +maven

来源:互联网 发布:超级电子仿真软件 编辑:程序博客网 时间:2024/06/06 01:20

1、junit4 测试插入数据时回滚

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:spring-mvc.xml", "classpath:spring-ctx-mybatis.xml", "classpath:spring-ctx-shiro.xml" })
public class SysVersionMapperTest {
@Autowired
private SysVersionMapper sysVersionMapper;

@Before
public void setUp() throws Exception {
}
@After
public void tearDown() throws Exception {
}
@Test
@Transactional
@Rollback(true)

public void testInsert() {
Map<String, Object> rd = new HashMap<>();
rd.put("sys_name", "Emt后台管理系统-工单处理");
rd.put("version", "3.0.0.1bete");
rd.put("describe", "更新内容:\n 1.实时查询订单 在专卖店系统内可以实时查询订单状态为关闭或待付款的订单,协助经销商发现潜在的客户");
rd.put("svn", "620");
rd.put("update_oper_code", "admin");
System.out.println("插入系统版本:" + sysVersionMapper.Insert(rd));
}

}

加入红色部分字体;加入后依然回滚不了报错: Manual close is not allowed over a Spring managed SqlSession;在sysSqlSession配置中加入scope

<bean id="sysSqlSession" class="org.mybatis.spring.SqlSessionTemplate"scope="prototype">
<constructor-arg index="0" ref="sysSqlSessionFactory" />
</bean>



亲测,ok


原创粉丝点击