我對Spring框架運行的J2EE應用程序。我正在使用AOP實現事務管理器。它工作正常。
當異常在我的方法它是由我的AOP配置中檢測到發生並回滾在DB中的變化。但問題在於你期望錯誤不應該被try-catch包圍的代碼。當我用try-catch包圍它時,它不會回滾。但是我需要做一些事情,比如每當有錯誤時記錄,我能想到的將它放在catch塊中的唯一位置。Spring的事務管理器
public class RegisterGLogic implements BLogic
{
public BLogicResult execute()
{
BLogicResult result = new BLogicResult();
//do some db operation
return result;
}
}
這裏是我的AOP事務配置
<bean id="TerasolunaDataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="PrototypeDataSource" />
</bean>
<tx:advice id="transactionInterceptor" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="insert*" propagation="REQUIRED"
rollback-for="java.lang.Exception" />
<tx:method name="execute*" propagation="REQUIRED"
rollback-for="java.lang.Exception" />
<tx:method name="*" propagation="REQUIRED" read-only="true" />
</tx:attributes>
</tx:advice>
<!-- AOPの設定 -->
<aop:config>
<aop:pointcut id="blogicBeans" expression="bean(*BLogic)" />
<aop:pointcut id="serviceBeans" expression="bean(*Service)" />
<aop:advisor pointcut-ref="blogicBeans" advice-ref="transactionInterceptor" />
<aop:advisor pointcut-ref="serviceBeans" advice-ref="transactionInterceptor" />
</aop:config>
怎麼樣給代碼? – Bozho 2010-03-23 15:53:43
我上面 – cedric 2010-03-23 17:20:36