Spring XML tx:advice相当于@TransactionConfiguration?
我在 Spring 3.0.5 中使用基于 XML 的事务配置。转向基于注释并不是一种选择。基于 XML 的配置中 @TransactionConfiguration( rollback=true) 的等价物是什么?
目前,我没有在 JUnit 中强制回滚,因此我的数据库始终充满必须删除/清理的随机测试数据。此外,我最终在不同的测试运行之间遇到了 PK 冲突。
我的 applicatonContext 内容如下:
...
<!-- 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>
...
如何指定我希望所有 JUnit 默认回滚?
谢谢,
埃里克
I'm using XML based transaction configuration in Spring 3.0.5. Moving to annotation based is not an option. What is the equivalent of @TransactionConfiguration( rollback=true) in XML based configuration?
At the moment, I am not enforcing rollbacks in my JUnits, so my DB is getting consistently full of random test data that must be dropped/cleaned. Additionally, I end up having PK conflicts between different test runs.
My applicatonContext 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 do I specify that I want all my JUnits to rollback by default?
Thanks,
Eric
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将这个配置放在您的 JUnit 测试类上。
我希望我已经为您提供了有关您问题的所有答案。
Put on your JUnit test class this configuration.
I hope I've given you all the answers about your question.