`

Was里面通过Spring配置分布式事务

阅读更多

1.登陆Was控制台,配置XA数据源,这有XA的数据源才可以支持分布式事务。

2.在xml里面配置dataSource和transactionManager,applicationContext-was.xml

<!-- JNDI DataSource -->
<jee:jndi-lookup id="dataSource" jndi-name="jdbc/db" />

<!-- Transaction manager for XA DataSource -->
<bean id="transactionManager" class="org.springframework.transaction.jta.WebSphereUowTransactionManager"/>

3.通过AOP实现将事务代理到指定的方法上,applicationContext-base.xml

 

<!-- Annotation Initilization -->
<context:annotation-config />

<!-- 扫描com.lq包里的接口 -->
<context:component-scan base-package="com.lq" scoped-proxy="interfaces" />

<aop:config>
    <!-- 代理com.lq.*.service.*Service命名的接口里的所有的方法 -->
    <aop:advisor id="managerTx" advice-ref="txAdvice"
          pointcut="execution(* *..service.*Service.*(..))" order="1" />
</aop:config>

<!-- enable the configuration of transactional behavior based on annotations -->
    <tx:annotation-driven  transactionmanager="transactionManager" />
    <!-- Transaction -->
	<tx:advice id="txAdvice" transaction-manager="transactionManager">
                    <tx:attributes>
	    <tx:method name="*" propagation="REQUIRED" />
	    <tx:method name="find*" read-only="true" />
	    <tx:method name="query*" read-only="true" />
	    </tx:attributes>
	</tx:advice>

 4.把这些xml文件放到web.xml中

   

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
        classpath*:conf/spring/applicationContext-base.xml
        classpath*:conf/spring/applicationContext-was.xml
    </param-value>
</context-param>

 

要实现分布式事务的两台机器都要配置名称相同的XA数据源。

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics