Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replacement of @TransactionConfiguration

Currently, I am using below configuration my test classes-

@TransactionConfiguration(transactionManager = "transactionManager", defaultRollback = false) 
@Transactional

As @TransactionConfiguration is deprecated, What can be the replacement for that-

I have tried -

@Transactional(transactionManager = "transactionManager")
@Commit

But I am getting the below error-

java.lang.IllegalStateException: Test class [ca.aeso.dt.dao.impl.AssetAttributeDaoImplTest] is annotated with both @Rollback and @TransactionConfiguration, but only one is permitted. at org.springframework.test.context.transaction.TransactionalTestExecutionListener.isDefaultRollback(TransactionalTestExecutionListener.java:383) at org.springframework.test.context.transaction.TransactionalTestExecutionListener.isRollback(TransactionalTestExecutionListener.java:412) at org.springframework.test.context.transaction.TransactionalTestExecutionListener.beforeTestMethod(TransactionalTestExecutionListener.java:201) at org.springframework.test.context.TestContextManager.beforeTestMethod(TestContextManager.java:269)

like image 484
user1638734 Avatar asked Apr 20 '17 12:04

user1638734


1 Answers

Yes, @Commit is equivalent to setting the default rollback mode to false.

In addition, the default name for the transaction manager is "transactionManager". So you can just delete the declaration of the qualifier and use @Transactional on its own.

If the exception is complaining about the use of @TransactionConfiguration, then you must have it declared somewhere, either on the test class or on a superclass. The solution is to simply delete the complete @TransactionConfiguration declaration.

Regards,

Sam (author of the Spring TestContext Framework)

like image 56
Sam Brannen Avatar answered Oct 30 '22 14:10

Sam Brannen