spring2.5+atomikos分布式事务配置

首先为src目录下的app_jta.xml(数据源及事务配置):
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">

<aop:config proxy-target-class="true">
<aop:pointcut id="serviceOperation" expression="execution(* com.service.impl.*.*(..))" />
<aop:advisor pointcut-ref="serviceOperation" advice-ref="txAdvice" />
</aop:config>

<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="del*" propagation="REQUIRED" rollback-for="Throwable"/>
<tx:method name="save*" propagation="REQUIRED" rollback-for="Throwable"/>
<tx:method name="update*" propagation="REQUIRED" rollback-for="Throwable"/>
<tx:method name="add*" propagation="REQUIRED" rollback-for="Throwable"/>
<tx:method name="create*" propagation="REQUIRED" rollback-for="Throwable"/>
<tx:method name="get*" read-only="true" />
<tx:method name="query*" read-only="true" />
<tx:method name="*" />
</tx:attributes>
</tx:advice>

<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath*:jdbc.properties</value>
</list>
</property>
</bean>

<bean id="dataSourceA" class="com.atomikos.jdbc.AtomikosDataSourceBean"
init-method="init" destroy-method="close">
<property name="uniqueResourceName" value="${mysqlA.uniqueResourceName}" />
<property name="xaDataSourceClassName" value="${mysql.xaDataSourceClassName}" />
<property name="xaProperties">
<props>
<prop key="user">${mysql.user}</prop>
<prop key="password">${mysql.password}</prop>
<prop key="URL">${mysqlA.url}</prop>
</props>
</property>
<property name="poolSize" value="${mysql.poolSize}" />
</bean>

<bean id="dataSourceB" class="com.atomikos.jdbc.AtomikosDataSourceBean"
init-method="init" destroy-method="close">
<property name="uniqueResourceName" value="${mysqlB.uniqueResourceName}" />
<property name="xaDataSourceClassName" value="${mysql.xaDataSourceClassName}" />
<property name="xaProperties">
<props>
<prop key="user">${mysql.user}</prop>
<prop key="password">${mysql.password}</prop>
<prop key="URL">${mysqlB.url}</prop>
</props>
</property>
<property name="poolSize" value="${mysql.poolSize}" />
</bean>

<bean id="atomikosTransactionManager" class="com.atomikos.icatch.jta.UserTransactionManager"
init-method="init" destroy-method="close">
<property name="forceShutdown" value="${transactionManager.forceShutdown}" />
</bean>

<bean id="atomikosUserTransaction" class="com.atomikos.icatch.jta.UserTransactionImp">
<property name="transactionTimeout" value="${transactionManager.transactionTimeout}" />
</bean>

<bean id="transactionManager"
class="org.springframework.transaction.jta.JtaTransactionManager">
<property name="transactionManager">
<ref bean="atomikosTransactionManager" />
</property>
<property name="userTransaction">
<ref bean="atomikosUserTransaction" />
</property>
</bean>

<!--
<tx:annotation-driven transaction-manager="transactionManager"
proxy-target-class="true" />
-->

<!-- dao -->
<bean id="userDaoA" class="com.dao.jdbc.UserJdbcDaoA">
<property name="dataSource" ref="dataSourceA" />
</bean>

<bean id="userDaoB" class="com.dao.jdbc.UserJdbcDaoB">
<property name="dataSource" ref="dataSourceB" />
</bean>

<bean id="userService" class="com.service.impl.UserServiceImpl">
<property name="userDaoA" ref="userDaoA" />
<property name="userDaoB" ref="userDaoB" />
</bean>

<bean id="userCtl" class="com.controller.UserController">
<property name="userService" ref="userService" />
</bean>

</beans>


接下来为WEB-INF下的spring-servlet.xml(SPRING MVC配置):

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">


<!-- 方法名解析器 -->
<bean id="InternalPathMethodNameResolver"
class="org.springframework.web.servlet.mvc.multiaction.InternalPathMethodNameResolver" />


<!-- 对模型视图名称的解析,在请求时模型视图名称添加前后缀 -->
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver"
p:prefix="/WEB-INF/jsp/" p:suffix=".jsp" />

<bean id="urlMapping"
class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<props>
<!-- partner -->
<prop key="/_new.do">userCtl</prop>
<prop key="/create.do">userCtl</prop>
</props>
</property>
</bean>
</beans>

以上为主要配置,另附完整实例,见附件。 :D
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值