<?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.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.0.xsd"
default-lazy-init="true">
<!-- JOTM 数据源
<bean id="jotm" class="com.demo.spring.jotm.jta.JotmFactoryBean" />
<bean id="springTransactionManager" class="org.springframework.transaction.jta.JtaTransactionManager">
<property name="userTransaction" ref="jotm" />
</bean>
<bean id="myDataSource1" class="org.enhydra.jdbc.pool.StandardXAPoolDataSource">
<property name="dataSource">
<bean class="org.enhydra.jdbc.standard.StandardXADataSource">
<property name="transactionManager">
<ref local="jotm" />
</property>
<property name="driverName">
<value>org.postgresql.Driver</value>
</property>
<property name="url">
<value>jdbc:postgresql://127.0.0.1:5432/test</value>
</property>
</bean>
</property>
<property name="user">
<value>postgres</value>
</property>
<property name="password">
<value>root</value>
</property>
<property name="maxSize">
<value>5</value>
</property>
<property name="minSize">
<value>2</value>
</property>
</bean>
<bean id="myDataSource2" class="org.enhydra.jdbc.pool.StandardXAPoolDataSource">
<property name="dataSource">
<bean class="org.enhydra.jdbc.standard.StandardXADataSource">
<property name="transactionManager">
<ref local="jotm" />
</property>
<property name="driverName">
<value>org.postgresql.Driver</value>
</property>
<property name="url">
<value>jdbc:postgresql://127.0.0.1:5432/news</value>
</property>
</bean>
</property>
<property name="user">
<value>postgres</value>
</property>
<property name="password">
<value>root</value>
</property>
<property name="maxSize">
<value>5</value>
</property>
<property name="minSize">
<value>2</value>
</property>
</bean>
-->
<!-- ATOMIKOS mysql 数据源
<bean id="myDataSource1" class="com.atomikos.jdbc.AtomikosDataSourceBean">
<property name="uniqueResourceName">
<value>MYSQL/test</value>
</property>
<property name="xaDataSourceClassName">
<value>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</value>
</property>
<property name="xaProperties">
<props>
<prop key="user">root</prop>
<prop key="password">root</prop>
<prop key="URL">jdbc:mysql://127.0.0.1:3306/test</prop>
</props>
</property>
</bean>
<bean id="myDataSource2" class="com.atomikos.jdbc.AtomikosDataSourceBean">
<property name="uniqueResourceName">
<value>MYSQL/news</value>
</property>
<property name="xaDataSourceClassName">
<value>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</value>
</property>
<property name="xaProperties">
<props>
<prop key="user">root</prop>
<prop key="password">root</prop>
<prop key="URL">jdbc:mysql://127.0.0.1:3306/news</prop>
</props>
</property>
</bean>
-->
<!-- ATOMIKOS postgres 数据源 -->
<bean id="myDataSource1" class="com.atomikos.jdbc.AtomikosDataSourceBean">
<property name="uniqueResourceName">
<value>postgre/test</value>
</property>
<property name="xaDataSourceClassName">
<value>org.postgresql.xa.PGXADataSource</value>
</property>
<property name="xaProperties">
<props>
<prop key="user">postgres</prop>
<prop key="password">root</prop>
<prop key="databaseName">test</prop>
<prop key="serverName">127.0.0.1</prop>
<prop key="portNumber">5432</prop>
</props>
</property>
</bean>
<bean id="myDataSource2" class="com.atomikos.jdbc.AtomikosDataSourceBean">
<property name="uniqueResourceName">
<value>postgre/news</value>
</property>
<property name="xaDataSourceClassName">
<value>org.postgresql.xa.PGXADataSource</value>
</property>
<property name="xaProperties">
<props>
<prop key="user">postgres</prop>
<prop key="password">root</prop>
<prop key="databaseName">news</prop>
<prop key="serverName">127.0.0.1</prop>
<prop key="portNumber">5432</prop>
</props>
</property>
</bean>
<bean id="sqlSessionFactory1" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="configLocation" value="classpath:config1.xml" />
<property name="dataSource" ref="myDataSource1" />
</bean>
<bean id="sqlSessionFactory2" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="configLocation" value="classpath:config2.xml" />
<property name="dataSource" ref="myDataSource2" />
</bean>
<bean id="userDAO" class="com.anxin.dao.impl.UserDAOImpl">
<property name="sqlSessionFactory" ref="sqlSessionFactory1" />
</bean>
<bean id="studentDAO" class="com.anxin.dao.impl.StudentDAOImpl">
<property name="sqlSessionFactory" ref="sqlSessionFactory2" />
</bean>
<bean id="studentService" class="com.anxin.service.impl.StudentServiceImpl">
<property name="dao" ref="studentDAO" />
</bean>
<bean id="userService" class="com.anxin.service.impl.UserServiceImpl">
<property name="dao" ref="userDAO" />
</bean>
<bean id="complexService" class="com.anxin.service.impl.ComplexServiceImpl">
<property name="userDao" ref="userDAO" />
<property name="studentDao" ref="studentDAO" />
</bean>
<!-- atomikosTransactionManager -->
<bean id="atomikosTransactionManager" class="com.atomikos.icatch.jta.UserTransactionManager"
init-method="init" destroy-method="close">
<property name="forceShutdown">
<value>true</value>
</property>
</bean>
<bean id="atomikosUserTransaction" class="com.atomikos.icatch.jta.UserTransactionImp">
<property name="transactionTimeout">
<value>300</value>
</property>
</bean>
<bean id="springTransactionManager" class="org.springframework.transaction.jta.JtaTransactionManager">
<property name="transactionManager">
<ref bean="atomikosTransactionManager" />
</property>
<property name="userTransaction">
<ref bean="atomikosUserTransaction" />
</property>
</bean>
<aop:config>
<aop:pointcut id="pc" expression="execution(* com.anxin.service.*.*(..))" />
<aop:advisor advice-ref="txAdvice" pointcut-ref="pc" />
</aop:config>
<tx:advice id="txAdvice" transaction-manager="springTransactionManager">
<tx:attributes>
<tx:method name="get*" propagation="REQUIRED" read-only="true" />
<tx:method name="find*" propagation="REQUIRED" read-only="true" />
<tx:method name="has*" propagation="REQUIRED" read-only="true" />
<tx:method name="locate*" propagation="REQUIRED" read-only="true" />
<tx:method name="*" propagation="REQUIRED" rollback-for="Exception" />
</tx:attributes>
</tx:advice>
<!-- 手动代理
<bean id="transactionProxyFactoryBean" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"
abstract="true">
<property name="transactionManager">
<ref bean="springTransactionManager" />
</property>
<property name="transactionAttributes">
<props>
<prop key="save*">PROPAGATION_REQUIRED,-Exception</prop>
</props>
</property>
</bean>
<bean id="complexServiceProxy" parent="transactionProxyFactoryBean">
<property name="target">
<ref bean="complexService" />
</property>
</bean>
-->
</beans>