Spring XML tx: advice @TransactionConfiguration equivalent?

I am using XML based transaction configuration in Spring 3.0.5. Switching to annotation is not an option. What is equivalent to @TransactionConfiguration (rollback = true) in an XML based configuration?

At the moment, I do not apply rollbacks in my JUnits, so my database is sequentially filled with random test data that needs to be deleted / cleaned. Also, I ended up encountering PK conflicts between different test runs.

My applatonContext reads as follows:

... <!-- Wrap all DAO Implementations in a transaction --> <aop:config proxy-target-class="false"> <aop:pointcut id="daoOperation" expression="execution(* com.calculator.dao.impl.*Impl.* (..))" /> <aop:advisor pointcut-ref="daoOperation" advice-ref="txAdvice" /> </aop:config> <tx:advice id="txAdvice"> <tx:attributes> <tx:method name="*" read-only="true" propagation="REQUIRED"/> <tx:method name="execute*" propagation="REQUIRED"/> <tx:method name="query*" propagation="REQUIRED"/> <tx:method name="insert" propagation="REQUIRED"/> <tx:method name="delete" propagation="REQUIRED"/> </tx:attributes> </tx:advice> <bean class="org.apache.commons.dbcp.BasicDataSource"> <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" /> <property name="url" value="${datasource.url}" /> <property name="username" value="${datasource.user}" /> <property name="password" value="${datasource.password}" /> <property name="defaultAutoCommit" value="false" /> </bean> ... 

How to indicate that I want all my JUnits to roll back by default?

Thanks,

Eric

+4
source share
1 answer

Put this configuration on your JUnit test class.

 @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = "/pathTo/spring/context/applicationContext.xml") @TransactionConfiguration(transactionManager = "transactionManager", defaultRollback = true) @Transactional public class LocationDaoTest extends AbstractTransactionalJUnit4SpringContextTests{ @Test public void testDAOsCRUD(){} } 

I hope I have given you all the answers to your question.

+1
source

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


All Articles