简体   繁体   English

Spring 声明式事务管理:多个切入点

[英]Spring declarative transaction management : multiple pointcuts

I know its almost weekend but still worth trying:)我知道它几乎是周末,但仍然值得一试:)

I need to use multiple transaction managers due to which it makes sense for me to go with declarative transactions management instead of using tx:annotation-driven.我需要使用多个事务管理器,因此使用声明性事务管理而不是使用 tx:annotation-driven go 对我来说很有意义。 However, I have service classes in various packages and the following config does not work:但是,我在各种包中有服务类,并且以下配置不起作用:

<bean id="transactionManager"
    class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    <property name="dataSource" ref="ds" />
    <property name="sessionFactory" ref="sessionFactory" />
</bean>

<tx:advice id="txAdvice" transaction-manager="transactionManager">
    <tx:attributes>
        <tx:method name="*" propagation="REQUIRED" />
    </tx:attributes>
</tx:advice>

<aop:config>
    <aop:pointcut id="svcPointcut1" expression="execution(* com.app.services.*.*(..))"/>
    <aop:pointcut id="svcPointcut2" expression="execution(* com.app.campaigns.services..*.*(..))"/>
    <aop:advisor advice-ref="txAdvice" pointcut-ref="svcPointcut1" />
    <aop:advisor advice-ref="txAdvice" pointcut-ref="svcPointcut2" />
</aop:config>

Could someone please tell me why only first pointcut works and the second one doesn't?有人可以告诉我为什么只有第一个切入点有效而第二个无效? The service methods in com.app.services package execute in the context of a transaction but the service methods in com.app.campaigns.services (and the sub-package below it) throw UnsupportedException. com.app.services package 中的服务方法在事务的上下文中执行,但 com.app.campaigns.serviceedException 中的服务方法抛出 UnsupportedException(以及它下面的)。 Please get me out of this misery!请让我摆脱这种痛苦! Thanks a ton!万分感谢!

PS: The application uses Spring 2.5.6 PS:应用使用Spring 2.5.6

I need to use multiple transaction managers due to which it makes sense for me to go with declarative transactions management instead of using tx:annotation-driven.我需要使用多个事务管理器,因此使用声明性事务管理而不是使用 tx:annotation-driven go 对我来说很有意义。

Both of those qualify as "declarative" transaction management.这两者都符合“声明性”事务管理的条件。 More importantly, though, you can still use annotation-driven transactions with multiple tx managers.不过,更重要的是,您仍然可以将注释驱动的事务与多个 tx 管理器一起使用。 Just give the name or qualifier of the manager as the "value" attribute of the annotation .只需将管理器的名称或限定符作为注释的“值”属性 With this XML:有了这个 XML:

<bean id="project1TransactionManager" class="...TransactionManager">
    <qualifier value="project1"/>
</bean>
<bean id="project2TransactionManager" class="...TransactionManager">
    <qualifier value="project2"/>
</bean>

Any of the following should work:以下任何一项都应该有效:

@Transactional("project1")
@Transactional("project1TransactionManager")
@Transactional("project2")
@Transactional("project2TransactionManager")

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

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