gpt4 book ai didi

Spring @Transactional 在 JUnit 测试中不起作用?

转载 作者:IT老高 更新时间:2023-10-28 13:58:01 25 4
gpt4 key购买 nike

我正在使用 Spring 3.2、Hibernate 和 JUnit 4。

我的Dao类如下:

@Transactional 公共(public)类 SomeDaoImpl 实现 SomeDao {

如果直接从 Web 应用程序执行此工作的更新操作。但是,我看到执行更新方法的 junit 集成测试实际上并没有持久化更改。执行 junit 方法时是否会回滚事务?

最佳答案

作者 reference ,事务在 Spring 的测试上下文中持久化。如前所述,虽然不寻常,但如果您仍然需要这样做,您可以使用 @TransactionConfiguration@Rollback更改默认行为。

关于Spring @Transactional 在 JUnit 测试中不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10718916/

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