我对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