开发者社区 问答 正文

[@talishboy][¥20]spring 3.1.2 中怎么使用 aop配置多个数据源,并且每个数据源的事务独立.







rollback-for="Exception" />
rollback-for="Exception" />
rollback-for="Exception" />
rollback-for="Exception" />
timeout="36000" />
timeout="36000" />
timeout="36000" />
timeout="36000" />




expression="execution( com.abc..Service.*(..))" />

单个数据源我一般这么配置,如果是多个数据源,怎么配置,spring3支持 @Transactional 配置多个数据源,不知道使用xml怎么配置,我主要是想使用 aop的expression 这样拦截包比较方便

spring 3 怎么配置多个数据源事务?

展开
收起
晓生寒 2018-12-14 15:45:32 3148 分享 版权
1 条回答
写回答
取消 提交回答
    1. 配置不同的TransactionManager
    2. 配置不同的Advice
    3. 配置不同的pointcut
      ----------- 例如 ---------

    <property name="dataSource" ref="dataSource1" />


    <property name="dataSource" ref="dataSource2" />

    <tx:attributes>
        <tx:method name="get*" propagation="NOT_SUPPORTED" />
        <tx:method name="save*" propagation="REQUIRED" rollback-for="Exception"/>
        <tx:method name="del*" propagation="REQUIRED" rollback-for="Exception" />
        <!-- ... -->
    </tx:attributes>


    <tx:attributes>
        <tx:method name="get*" propagation="NOT_SUPPORTED" />
        <tx:method name="save*" propagation="REQUIRED" rollback-for="Exception"/>
        <tx:method name="del*" propagation="REQUIRED" rollback-for="Exception" />
        <!-- ... -->
    </tx:attributes>

    <aop:pointcut id="transcationPointcut1" expression="execution(* com.test1.service.impl.*.*(..))"/>
    <aop:pointcut id="transcationPointcu2t" expression="execution(* com.test2.service.impl.*.*(..))"/>
    <aop:advisor pointcut-ref="transcationPointcut1" advice-ref="txAdvice1" />
    <aop:advisor pointcut-ref="transcationPointcut2" advice-ref="txAdvice2" />

    2019-07-17 23:21:02
    赞同 展开评论