6

为什么没有回滚事务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

做错了什么?如有必要,我可以提供更多信息。

4

1 回答 1

11

INFO级别应该提示这不是错误消息。无论服务级别方法的主要设置如何,您的测试都会默认回滚。为了避免回滚(如果你真的想要),你需要在测试类本身上添加一个注解,如Spring 文档中测试章节的注解部分所述。有问题的注释是@Rollback.

于 2013-10-12T12:21:51.420 回答