日期:2014-05-17  浏览次数:20906 次

Spring分布式事务在service中无法动态切换数据源
Spring分布式事务在service中无法切换数据源
项目采用的是struts2+spring+ibatis架构,下面是关键部分代码:

applicationContext.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: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" 
   default-autowire="byName" default-lazy-init="false">
    
<context:component-scan base-package="com.ssi.*" />
<!-- 属性文件读入 -->
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath*:jdbc.properties</value>
</list>
</property>
</bean>
<!-- JTA 数据源配置 -->
<bean id="center" class="com.atomikos.jdbc.AtomikosDataSourceBean" init-method="init" destroy-method="close">
<property name="uniqueResourceName">
<value>mysql/center</value>
</property>
<property name="xaDataSourceClassName">
<value>${jta.driver.className}</value>
</property>
<property name="xaProperties">
<props>
<prop key="url">${center.jdbc.driver.url}</prop>
<prop key="user">${center.sql.user.name}</prop>
<prop key="password">${center.sql.user.password}</prop>
</props>
</property>
<property name="testQuery" value="select 1" />
<property name="poolSize">