Spring transactionManager is Rolling back, while testexception=[null]!

可紊 提交于 2020-01-23 08:55:54

问题


Why is the transaction being rolled back while there is no Exception? The object is not being saved. I have defined the transaction parameters like:

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

This is what logs say about the transaction.

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

Here is the whole log of DAOTest class:

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

what's being done wrong? I can give more information if necessary.


回答1:


The INFO level should give a hint that this is not an error message. Your test rolls back by default, regardless of the primary setting on the service-level method. To avoid rollback (if you really want to) you need an annotation on the test class itself, as documented in the Annotations section of the Testing chapter in Spring documentation. The annotation in question is @Rollback.



来源:https://stackoverflow.com/questions/19333955/spring-transactionmanager-is-rolling-back-while-testexception-null

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!