2013-10-12 84 views
1

爲什麼交易在沒有Exception的情況下回滾?該對象未被保存。 我已經定義了交易參數,如:Spring transactionManager正在回滾,而testexception = [null]!

@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 [[email protected] 
testClass = DAOTest, testInstance = [email protected], testMethod = 
[email protected], testException = [null], mergedContextConfiguration = 
[[email protected] 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

INFO級別應該提示這不是錯誤消息。無論服務級別方法的主要設置如何,默認情況下您的測試都會回滾。爲了避免回滾(如果你真的想要),你需要在測試類本身上註釋,如Spring文檔中的Annotations section of the Testing chapter所述。有問題的註釋是@Rollback

相關問題