Automatically rollback @Transactional transaction in Spring 3?

I work as a unit test, and it automatically returns, even if I do not use @rollback in spring 3.1. My test looks like

 @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = { "classpath:application-context.xml" }) public class PersonServiceTest { @Test @Transactional public void savePerson() { Person person = createPerson(); personService.savePerson(person); } } 

Is rollback set to default?

+6
source share
1 answer

By default, SpringJUnit4ClassRunner automatically rolls back transactions.

To cancel the effect, use @TransactionConfiguration(defaultRollback=false) in the test class or @Rollback(false) for each test.

+13
source

Source: https://habr.com/ru/post/922132/


All Articles