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