gpt4 book ai didi

java - Spring transactionManager 正在回滚,而 testexception=[null]!

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:56:34 25 4
gpt4 key购买 nike

为什么在没有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

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

最佳答案

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

关于java - Spring transactionManager 正在回滚,而 testexception=[null]!,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19333955/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com