67,550
社区成员




<?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:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">
<context:component-scan base-package="com.al.persistence.testcase.bmo.impl"/>
<!-- 第一个数据库 -->
<bean id="dataSource1" class="com.atomikos.jdbc.AtomikosDataSourceBean" init-method="init" destroy-method="close">
<property name="uniqueResourceName" value="oracle1"/>
<property name="xaDataSourceClassName" value="oracle.jdbc.xa.client.OracleXADataSource"/>
<property name="xaProperties">
<props>
<prop key="user">sr</prop>
<prop key="password">sr</prop>
<prop key="URL">jdbc:oracle:thin:@192.168.74.15:1522:jttest</prop>
</props>
</property>
</bean>
<!-- 第二个数据库 -->
<bean id="dataSource2" class="com.atomikos.jdbc.AtomikosDataSourceBean" init-method="init" destroy-method="close">
<property name="uniqueResourceName" value="oracle2"/>
<property name="xaDataSourceClassName" value="oracle.jdbc.xa.client.OracleXADataSource"/>
<property name="xaProperties">
<props>
<prop key="user">crm</prop>
<prop key="password">crm</prop>
<prop key="URL">jdbc:oracle:thin:@192.168.74.15:1522:jttest</prop>
</props>
</property>
</bean>
<!-- 持久层数据库操作主类 -->
<bean class="com.al.persistence.routing.RoutingSqlSessionFactoryBean">
<property name="targetDataSources">
<map>
<entry key="ds2" value-ref="dataSource2"/>
<entry key="ds1" value-ref="dataSource1"/>
</map>
</property>
<property name="strategy" value="com.al.persistence.testcase.routing.RoutingSessionStrategy"/><!-- 分库策略实现类 -->
<property name="configLocation" value="classpath:ibatis/configuration.xml"/>
</bean>
<bean class="com.al.persistence.ExtMapperScannerConfigurer">
<property name="basePackage" value="com.al.persistence.testcase.mapper"/>
</bean>
<!-- JTA事务 -->
<bean id="atomikosTransactionManager" class="com.atomikos.icatch.jta.UserTransactionManager" init-method="init" destroy-method="close">
<property name="forceShutdown" value="true"/>
</bean>
<bean id="atomikosUserTransaction" class="com.atomikos.icatch.jta.UserTransactionImp">
<property name="transactionTimeout" value="300"/>
</bean>
<bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager">
<property name="transactionManager" ref="atomikosTransactionManager"/>
<property name="userTransaction" ref="atomikosUserTransaction"/>
</bean>
<aop:config proxy-target-class="true">
<aop:advisor pointcut="execution(* com.al.persistence.testcase.bmo.impl.*.*(..))" advice-ref="txAdvice"/>
</aop:config>
<tx:advice id="txAdvice">
<tx:attributes>
<tx:method name="insert*"/>
<tx:method name="update*"/>
<tx:method name="delete*"/>
<tx:method name="get*" read-only="true"/>
</tx:attributes>
</tx:advice>
</beans>
<!-- 配置JNDI -->
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="${sr.jndiDataSource}"></property>
</bean>