Reputation: 1549
I have updated my pom from spring-boot-starter-parent 1.2.5.RELEASE to 1.3.2.RELEASE.
The problem is that everything stay the same but all the test @Rollback(true)
not working at all after migration.
@Transactional
@Rollback(true)
@Test
public void testRollBack() {
dao.saveToDb();
throw new RunTimeException();
}
Configaturation:
@Bean
@Primary
public PlatformTransactionManager txManager() {
return new DataSourceTransactionManager(dataSource());
}
It works perfectly in the same configuration and code and the only change is spring boot version. I cannot see that Transaction is being created in logs as suppose too
Anyone has a clue? Maybe a way to debug and understand what is the problem?
Thanks
Upvotes: 1
Views: 1723
Reputation: 1549
I have put spring on debug.. There is a problem/bug in the test framework or i don't understand the use correctly. I checked the code of spring and saw this:
bf.getBean(DEFAULT_TRANSACTION_MANAGER_NAME, PlatformTransactionManager.class);
This happens when we have several transaction manager, instead of getting the bean marked by @Primary
annotation spring try to get transaction manager that called "transactionManager".
The solution is just mark the bean in that name.. Tried to open issue to spring-test project but don't know where.. If anyone knows how please advise.
Thanks
EDIT: So the solution is eiether what i have wrote above or just name them transaction(@Transactional("myManager")
) and use it in the test method signature
Upvotes: 0
Reputation: 116261
TransactionTestExecutionListener
has changed quite a lot between Spring Framework 4.1 (used by Spring Boot 1.2) and Spring Framework 4.2 (used by Spring Boot 1.3). It sounds like there's been a change in behaviour which I suspect probably wasn't intentional.
To fix your problem without renaming one of your beans, you need to tell the test framework which transaction manager to use. The easiest way to do that is via the @Transactional
annotation:
@Transactional("txManager")
@Rollback(true)
@Test
public void testRollBack() {
dao.saveToDb();
throw new RunTimeException();
}
Upvotes: 3