Junit测试事务,没异常就回滚了

liyuguanguan 2017-05-04 11:52:56
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration({"classpath:spring-mvc.xml","classpath:spring-mybatis.xml"})
public class aa {

@Autowired
private CeShiImpl ceShiImpl;
@Test
@Transactional
public void aa() throws Exception{
CeShi ceShi = new CeShi();
ceShi.setA("20");
ceShiImpl.AA(ceShi);//只是一个update的方法

}


}

下面是控制台信息
2017-05-04 11:15:17 [org.springframework.beans.factory.xml.XmlBeanDefinitionReader]-[INFO] Loading XML bean definitions from class path resource [spring-mvc.xml]
2017-05-04 11:15:18 [org.springframework.beans.factory.xml.XmlBeanDefinitionReader]-[INFO] Loading XML bean definitions from class path resource [spring-mybatis.xml]
2017-05-04 11:15:18 [org.springframework.context.support.GenericApplicationContext]-[INFO] Refreshing org.springframework.context.support.GenericApplicationContext@4475a0c6: startup date [Thu May 04 11:15:18 CST 2017]; root of context hierarchy
2017-05-04 11:15:19 [org.springframework.beans.factory.config.PropertyPlaceholderConfigurer]-[INFO] Loading properties file from class path resource [jdbc.properties]
2017-05-04 11:15:19 [org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor]-[INFO] JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
2017-05-04 11:15:21 [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping]-[INFO] Mapped "{[/DataImportAction/manientry],methods=[POST],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String cn.haiwaigo.epm.controller.DataImportController.ManiEntry(java.lang.String) throws java.lang.Exception
2017-05-04 11:15:21 [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping]-[INFO] Mapped "{[/map/getDistrict],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String cn.haiwaigo.epm.controller.MapController.getDistrict()
2017-05-04 11:15:21 [org.hibernate.validator.internal.util.Version]-[INFO] HV000001: Hibernate Validator 5.2.4.Final
2017-05-04 11:15:22 [org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor]-[INFO] Initializing ExecutorService 'taskExecutor'
2017-05-04 11:15:33 [org.springframework.test.context.transaction.TransactionalTestExecutionListener]-[INFO] Began transaction (1) for test context [DefaultTestContext@70e9311d testClass = aa, testInstance = MybatisTool.aa@5d97a0d4, testMethod = aa@aa, testException = [null], mergedContextConfiguration = [MergedContextConfiguration@dbfee4d testClass = aa, locations = '{classpath:spring-mvc.xml, classpath:spring-mybatis.xml}', classes = '{}', contextInitializerClasses = '[]', activeProfiles = '{}', contextLoader = 'org.springframework.test.context.support.DelegatingSmartContextLoader', parent = [null]]]; transaction manager [org.springframework.jdbc.datasource.DataSourceTransactionManager@33b60848]; rollback [true]
2017-05-04 11:15:33 [cn.haiwaigo.epm.mybatis.mapper.CeShiMapper.insertSelective]-[DEBUG] ==> Preparing: insert into CESHI ( A ) values ( ? )
2017-05-04 11:15:33 [cn.haiwaigo.epm.mybatis.mapper.CeShiMapper.insertSelective]-[DEBUG] ==> Preparing: insert into CESHI ( A ) values ( ? )
2017-05-04 11:15:33 [cn.haiwaigo.epm.mybatis.mapper.CeShiMapper.insertSelective]-[DEBUG] ==> Parameters: 20(String)
2017-05-04 11:15:33 [cn.haiwaigo.epm.mybatis.mapper.CeShiMapper.insertSelective]-[DEBUG] ==> Parameters: 20(String)
2017-05-04 11:15:33 [cn.haiwaigo.epm.mybatis.mapper.CeShiMapper.insertSelective]-[DEBUG] <== Updates: 1
2017-05-04 11:15:33 [cn.haiwaigo.epm.mybatis.mapper.CeShiMapper.insertSelective]-[DEBUG] <== Updates: 1
2017-05-04 11:15:33 [org.springframework.test.context.transaction.TransactionalTestExecutionListener]-[INFO] Rolled back transaction after test execution for test context [DefaultTestContext@70e9311d testClass = aa, testInstance = MybatisTool.aa@5d97a0d4, testMethod = aa@aa, testException = [null], mergedContextConfiguration = [MergedContextConfiguration@dbfee4d testClass = aa, locations = '{classpath:spring-mvc.xml, classpath:spring-mybatis.xml}', classes = '{}', contextInitializerClasses = '[]', activeProfiles = '{}', contextLoader = 'org.springframework.test.context.support.DelegatingSmartContextLoader', parent = [null]]]
2017-05-04 11:15:33 [org.springframework.context.support.GenericApplicationContext]-[INFO] Closing org.springframework.context.support.GenericApplicationContext@4475a0c6: startup date [Thu May 04 11:15:18 CST 2017]; root of context hierarchy
2017-05-04 11:15:33 [org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor]-[INFO] Shutting down ExecutorService 'taskExecutor'


想问下没有异常为什么会直接回滚了呢??
...全文
402 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
liyuguanguan 2017-05-04
  • 打赏
  • 举报
回复
问题已经解决,发现原因是因为单元测试用到的是Spring-test,而test就是为了让数据不会滚,以防止单元测试污染数据库而做的设定.

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧