10

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)

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
user1638734
  • 101
  • 1
  • 1
  • 4

1 Answers1

10

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)

Sam Brannen
  • 29,611
  • 5
  • 104
  • 136