2010-03-23 112 views
0

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

怎么样给代码? – Bozho 2010-03-23 15:53:43

+0

我上面 – cedric 2010-03-23 17:20:36

回答

0

登录后可以重新抛出异常。这将使Spring进行回滚。

0

首先,你为什么不使用内置事务管理器?他们肯定比你更稳定。

其次,你可以重新抛出一个RuntimeException我猜想,甚至让异常泡沫了。

+0

更新我已经使用了内置的DataSourceTransactionManager,等我的方法,我想回滚做的是一类特定的框架的覆盖方法尝试。我在这里使用terasoluna框架。这是来自日本的框架。当我重新抛出异常时,我收到一个错误,说明没有处理异常。我也不允许在重写方法 – cedric 2010-03-23 17:10:13

+0

中添加thorws,为什么不使用'DataSourceTransactionManager'? – Bozho 2010-03-23 17:47:04

+0

我已经是。我回去使用它 – cedric 2010-03-24 01:06:30