【问题标题】:Spring AOP and transaction add custom interceptorsSpring AOP 和事务添加自定义拦截器
【发布时间】:2010-09-14 15:46:44
【问题描述】:

我关于事务的 spring 定义如下:

<bean id="txInterceptor"
    class="org.springframework.transaction.interceptor.TransactionInterceptor">
    <property name="transactionManager" ref="transactionManager"/>
</bean>

<aop:config>
    <aop:pointcut id="defaultServiceOperation"
          expression="execution(* x.y.service.*Service.*(..))"/>
    <aop:advisor pointcut-ref="defaultServiceOperation"
          advice-ref="defaultTxAdvice"/>
</aop:config>

<tx:advice id="defaultTxAdvice">
    <tx:attributes>                        
         <tx:method name="*"/>
    </tx:attributes>
</tx:advice>

现在,我想添加一些我的应用程序包含的额外拦截器,它们将在每次调用该事务拦截器之前运行。即我想将其他建议添加到切入点“defaultServiceOperation”,或添加到“defaultTxAdvice”预拦截器。比如:

<property name="preInterceptors">
      <list>
           <ref bean="optimisticLockingInterceptor"/>
           <ref bean="deadLockingInterceptor"/>            
      </list>
</property>

有可能吗?我该怎么做?

【问题讨论】:

  • 是问题不清楚还是Spring不支持这种模式,没有解决方案?

标签: java spring transactions spring-aop


【解决方案1】:

你可以提供多少个拦截器,TransactionInterceptor 应该在你提到的拦截器列表中首先提供。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-10-04
    • 2018-01-31
    • 2023-03-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多