多数据库

分布式事务/ 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)");
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值