简体   繁体   English

Spring交易管理txAdvice

[英]Spring transaction management txAdvice

I've got some trouble while configuring spring transaction manager. 在配置Spring事务管理器时遇到了一些麻烦。 The application I'm working on has a layered architecture. 我正在处理的应用程序具有分层的体系结构。 Therefore it has a service layer containing all the transactional services. 因此,它具有一个包含所有事务服务的服务层。 I wanted for spring to rollback the transaction when a checked (application specific) exception has occurred. 我希望Spring在发生检查(特定于应用程序)异常时回滚事务。 I succeeded doing that by annotation as follows: 我通过注释成功完成了如下操作:

@Transactional(value="transactionDds", rollbackfor="Throwable") @Transactional(value =“ transactionDds”,rollbackfor =“ Throwable”)

This works fine. 这很好。 But since I've so many services hence I want to move this configuration to XML (spring DAO context file). 但是由于我有很多服务,因此我想将此配置移到XML(Spring DAO上下文文件)。 This is what I've done: 这是我所做的:

<tx:advice id="txAdvice" transaction-manager="transactionManagerDds">
    <tx:attributes>
        <tx:method name="*" read-only="false" propagation="REQUIRED" rollback-for="Throwable"/>
    </tx:attributes>
 </tx:advice>
 <aop:config>
    <aop:pointcut id="transRollbackOp" expression="execution(*fr.def.iss.ult.moduleManagement.service.dds.*.*.*(..))"/>
    <aop:advisor advice-ref="txAdvice" pointcut-ref="transRollbackOp"/>
  </aop:config> 

  <bean id="transactionManagerDds" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">  
     <property name="dataSource" ref="beanDataSourceFactory" />  
      <qualifier value="transactionDds"/> 
  </bean>

So basically, I'va a transaction manager which is associated to an advice which rolls back for the possible methods when a Throwable exception occurs. 因此,基本上,我是一个事务管理器,它与一个建议相关联,当Throwable异常发生时,该建议会回滚为可能的方法。 And this advice is linked to an AOP config that way we specify all the interfaces in the service layer of application on which this transaction configuration is to be applied. 并且此建议链接到AOP配置,这样我们可以在应用程序的服务层中指定要应用此事务配置的所有接口。 But this doesn't work. 但这是行不通的。 Transaction doesn't roll back Throwable exception occurs. 事务不会回滚发生Throwable异常。 I don't understand that this works with annotation but not with declarative configuration in XML. 我不明白这适用于注释,但不适用于XML中的声明式配置。

I'm really looking forward for your suggestions. 我真的很期待您的建议。 I'm totally blocked. 我完全被封锁了。 Plz help me out. 请帮我。 Thanx in advance. 提前感谢。

<aop:config>
    <aop:pointcut id="transRollbackOp" expression="execution(*fr.def.iss.ult.moduleManagement.service.dds.*.*.*(..))"/>
    <aop:advisor advice-ref="txAdvice" pointcut-ref="transRollbackOp"/>
</aop:config>

In your <aop:config /> the expression you entered is invalid. <aop:config /> ,您输入的表达式无效。 It should at least contain a whitespace between * and fr.def . 它至少应在*fr.def之间包含一个空格。

Next instead of .*.*.* I suggest writing ..*.* which selects all classes in all subpackages regardless of depth. 接下来,我建议编写..*.*而不是.*.*.*来选择所有子包中的所有类,而不考虑其深度。

In short change your expression to execution(* fr.def.iss.ult.moduleManagement.service.dds..*.*(..)) should make it work. 简而言之,将您的表达式更改为execution(* fr.def.iss.ult.moduleManagement.service.dds..*.*(..))应该可以使它起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM