分布式事务/ oracle 一个实例/ mysql 多个数据库
com.zaxxer.hikari.HikariDataSource
com.alibaba.druid.pool.DruidDataSource
https://www.cnblogs.com/jiangyu666/p/8522547.html . ==
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<!-- 我们的测试用例中模拟了跨两个数据库的情况,所以指定了两个数据源 -->
<bean id="txcDataSource1" class="com.taobao.txc.datasource.cobar.TxcDataSource">
<property name="url" value="jdbc:mysql://bxxx:23306/pangtx1" />
<property name="username" value="xx" />
<property name="password" value="xxx" />
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
</bean>
<bean id="txcDataSource3" class="com.taobao.txc.datasource.cobar.TxcDataSource">
<property name="url" value="jdbc:oracle:thin:@xxxx:1521:orcl" />
<property name="username" value="xxxx" />
<property name="password" value="Bxxx" />
<property name="driverClassName" value="oracle.jdbc.OracleDriver" />
</bean>
<bean id="jdbcTemplate1" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="txcDataSource1" />
</bean>
<bean id="jdbcTemplate3" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="txcDataSource3" />
</bean>
<bean id="txcDataSource2" class="com.taobao.txc.datasource.cobar.TxcDataSource" >
<property name="url" value="jdbc:mysql://bbbbb:3306/pangtx2" />
<property name="username" value="ss" />
<property name="password" value="sss" />
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
</bean>
<bean id="txcDataSource4" class="com.taobao.txc.datasource.cobar.TxcDataSource">
<property name="url" value="jdbc:oracle:thin:@xxxxxx:1521:orcl" />
<property name="username" value="xxx" />
<property name="password" value="Bxxxx" />
<property name="driverClassName" value="oracle.jdbc.OracleDriver" />
</bean>
<bean id="jdbcTemplate2" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="txcDataSource2" />
</bean>
<bean id="jdbcTemplate4" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="txcDataSource4" />
</bean>
<!-- 定义声明式事务,要想让事务annotation感知的话,要在这里定义一下,spring才能感知到噢 -->
<bean class="com.taobao.txc.client.aop.TxcTransactionScaner">
<constructor-arg value="myapp"/><!-- 应用名,用户自定义 -->
<constructor-arg value="txc_test_public.1129361738553704.QD"/><!-- 事务分组名 -->
<constructor-arg value="1" />
<constructor-arg value="https://test-cs-gts.aliyuncs.com" />
</bean>
<bean id="clientTest" class="com.taobao.txc.test.Simple" />
</beans>
======
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("txc-client-context.xml");
Simple simple = (Simple) context.getBean("clientTest");
jdbcTemplate1 = (JdbcTemplate)context.getBean("jdbcTemplate1");
jdbcTemplate2 = (JdbcTemplate)context.getBean("jdbcTemplate2");
jdbcTemplate1.update("insert into testtx1(id) values (1)");