Hi,
I'm trying to convert my test classes to use the @Transactional annotation instead of extending AbstractTransactionalJUnit4SpringContextTests and using @NotTransactional. This is the recommended approach, according to SPR-6043.
But, for some reason, I cannot get the @Transactional annotation to do anything! When I put a breakpoint in the test method annotated by @Transactional, I cannot see TransactionInterceptor in the stack trace, as I expect to. In fact, I do not see the test class is proxied at all.
What am I doing wrong?
Here’s my application context XML:
And here’s a simplified test class, based on the example from http://static.springsource.org/sprin...testcontext-tx:Code:<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"> <tx:annotation-driven transaction-manager="transactionManager" /> <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager" lazy-init="default"> <property name="sessionFactory"> <ref bean="sessionFactory" /> </property> </bean> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" lazy-init="default"> <!-- connection configuration --> <property name="driverClassName" value="org.postgresql.Driver" /> <property name="url" value="jdbc:postgresql://localhost:5432/mydb" /> <property name="username" value="user" /> <property name="password" value="pass" /> </bean> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean" lazy-init="default"> <property name="dataSource"> <ref bean="dataSource" /> </property> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</prop> <prop key="hibernate.show_sql">false</prop> <prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop> <prop key="hibernate.cache.use_second_level_cache">false</prop> <prop key="hibernate.cache.use_query_cache">false</prop> </props> </property> </bean> </beans>
Any idea?Code:import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.transaction.TransactionConfiguration; import org.springframework.transaction.annotation.Transactional; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration @TransactionConfiguration(transactionManager="transactionManager", defaultRollback=true) public class FictitiousTransactionalTest { @Test @Transactional public void modifyDatabaseWithinTransaction() { System.out.println(); } }
Thanks,
Moshe


Reply With Quote
