为什么在没有Exception
的情况下回滚事务?该对象未被保存。
我已经定义了交易参数,如:
@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
做错了什么?如有必要,我可以提供更多信息。
答案 0 :(得分:8)
INFO
级别应该提示这不是错误消息。无论服务级别方法的主要设置如何,您的测试都会默认回滚。为了避免回滚(如果你真的想要),你需要在测试类本身上有一个注释,如Spring文档中的Annotations section of the Testing chapter中所述。有问题的注释是@Rollback
。