如何在Spring Boot测试中强制事务提交?
2022-09-04 06:59:11
如何在运行方法时在Spring Boot(使用Spring Data)中强制提交事务,而不是在方法之后?
我在这里读到过,它应该可以在另一个班级中使用,但对我不起作用。@Transactional(propagation = Propagation.REQUIRES_NEW)
任何提示?我正在使用Spring Boot v1.5.2.RELEASE。
@RunWith(SpringRunner.class)
@SpringBootTest
public class CommitTest {
@Autowired
TestRepo repo;
@Transactional
@Commit
@Test
public void testCommit() {
repo.createPerson();
System.out.println("I want a commit here!");
// ...
System.out.println("Something after the commit...");
}
}
@Repository
public class TestRepo {
@Autowired
private PersonRepository personRepo;
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void createPerson() {
personRepo.save(new Person("test"));
}
}