Spring事务管理器正在回滚,同时testexception = [null]!

6

在没有异常的情况下,为什么事务被回滚了呢?该对象未被保存。 我已经定义了事务参数如下:

 @Transactional(value = "transactionManager", timeout = 30, rollbackFor =
 java.lang.Exception.class)`.  

这是有关交易的日志记录。
org.springframework.test.context.transaction.TransactionalTestExecutionListener
endTransaction
INFO: Rolled back transaction after test execution for test context [TestContext@51e2a069
testClass = DAOTest, testInstance = sample.library.dao.DAOTest@7591777e, testMethod =
testSaveDao@DAOTest, testException = [null], mergedContextConfiguration =
[MergedContextConfiguration@213c2d7f testClass = DAOTest, locations = 
'{classpath:/applicationcontext.xml}', classes = '{}', contextInitializerClasses = '[]',
activeProfiles = '{}', contextLoader = 
'org.springframework.test.context.support.DelegatingSmartContextLoader', parent =
[null]]]
Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 3.634 sec

这里是DAOTest类的完整日志:

-------------------------------------------------------------------------------
Test set: sample.library.dao.DAOTest
-------------------------------------------------------------------------------
Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 3.634 sec

错误出在哪里?如果需要,我可以提供更多信息。
1个回答

11

INFO级别应该是一个提示,表明这不是一个错误消息。无论服务级别方法上的主设置如何,默认情况下,您的测试都会回滚。如果您真的想要避免回滚,则需要在测试类本身上放置一个注释,如Spring文档的测试章节中的注释部分所述。相应的注释是@Rollback


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接