Druid中配置双数据库
配置如下
<?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:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-3.2.xsd"
default-autowire-candidates="byType"> <!--
单数据源
-->
<!--
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"
init-method="init" destroy-method="close">
<property name="driverClassName">
<value>${dbDriver}</value>
</property>
<property name="url">
<value>${dbUrl}</value>
</property>
<property name="username">
<value>${dbUsername}</value>
</property>
<property name="password">
<value>${dbPassword}</value>
</property>
<property name="maxActive">
<value>${maxActive}</value>
</property>
<property name="initialSize">
<value>${initialSize}</value>
</property>
<property name="maxWait">
<value>${maxWait}</value>
</property>
<property name="minIdle">
<value>${minIdle}</value>
</property>
<property name="removeAbandoned">
<value>${removeAbandoned}</value>
</property>
<property name="removeAbandonedTimeout">
<value>${removeAbandonedTimeout}</value>
</property>
<property name="connectionProperties">
<value>${connectionProperties}</value>
</property>
<property name="logAbandoned" value="true" />
</bean> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"
p:dataSource-ref="dataSource" p:configLocation="classpath:common/mybatis-config.xml"
p:mapperLocations="classpath*:common/mapper/**/*.xml" />
-->
<!-- mybatis.spring自动映射 -->
<!--
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"
p:basePackage="com.niko.dao" p:sqlSessionFactoryBeanName="sqlSessionFactory" /> <bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager"
p:dataSource-ref="dataSource" /> <tx:annotation-driven transaction-manager="transactionManager" />
--> <!-- 多数据源 mysql 和 sqlserver 共存 --> <bean id="sqlServerDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${jdbc.sqlserver.driver}"/>
<property name="url" value="${jdbc.sqlserver.url}"/>
<property name="username" value="${jdbc.sqlserver.username}"/>
<property name="password" value="${jdbc.sqlserver.password}"/>
<property name="initialSize" value="${jdbc.initialSize}"/>
<property name="minIdle" value="${jdbc.minIdle}"/>
<property name="maxIdle" value="${jdbc.maxIdle}"/>
<property name="maxActive" value="${jdbc.maxActive}"/>
<property name="maxWait" value="${jdbc.maxWait}"/>
<property name="defaultAutoCommit" value="${jdbc.defaultAutoCommit}"/>
<property name="removeAbandoned" value="${jdbc.removeAbandoned}"/>
<property name="removeAbandonedTimeout" value="${jdbc.removeAbandonedTimeout}"/>
<property name="testWhileIdle" value="${jdbc.testWhileIdle}"/>
<property name="timeBetweenEvictionRunsMillis" value="${jdbc.timeBetweenEvictionRunsMillis}"/>
<property name="numTestsPerEvictionRun" value="${jdbc.numTestsPerEvictionRun}"/>
<property name="minEvictableIdleTimeMillis" value="${jdbc.minEvictableIdleTimeMillis}"/>
</bean>
<bean id="mySqlDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${jdbc.mysql.driver}"/>
<property name="url" value="${jdbc.mysql.url}"/>
<property name="username" value="${jdbc.mysql.username}"/>
<property name="password" value="${jdbc.mysql.password}"/>
<property name="initialSize" value="${jdbc.initialSize}"/>
<property name="minIdle" value="${jdbc.minIdle}"/>
<property name="maxIdle" value="${jdbc.maxIdle}"/>
<property name="maxActive" value="${jdbc.maxActive}"/>
<property name="maxWait" value="${jdbc.maxWait}"/>
<property name="defaultAutoCommit" value="${jdbc.defaultAutoCommit}"/>
<property name="removeAbandoned" value="${jdbc.removeAbandoned}"/>
<property name="removeAbandonedTimeout" value="${jdbc.removeAbandonedTimeout}"/>
<property name="testWhileIdle" value="${jdbc.testWhileIdle}"/>
<property name="timeBetweenEvictionRunsMillis" value="${jdbc.timeBetweenEvictionRunsMillis}"/>
<property name="numTestsPerEvictionRun" value="${jdbc.numTestsPerEvictionRun}"/>
<property name="minEvictableIdleTimeMillis" value="${jdbc.minEvictableIdleTimeMillis}"/>
</bean> <bean id="sqlserverSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"
p:dataSource-ref="sqlServerDataSource"
p:configLocation="classpath:common/mybatis-config.xml"
p:mapperLocations="classpath*:common/mapper/**/*.xml">
</bean> <bean id="mysqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"
p:dataSource-ref="mySqlDataSource"
p:configLocation="classpath:common/mybatis-config.xml"
p:mapperLocations="classpath*:common/mapper/**/*.xml">
</bean> <!-- mybatis.spring自动映射 -->
<bean id="sqlserverMSF" class="org.mybatis.spring.mapper.MapperScannerConfigurer"
p:basePackage="com.niko.dao.sqlserver" p:sqlSessionFactoryBeanName="sqlserverSessionFactory" /> <bean id="mysqlMSF" class="org.mybatis.spring.mapper.MapperScannerConfigurer"
p:basePackage="com.niko.dao.mysql" p:sqlSessionFactoryBeanName="mysqlSessionFactory" /> <bean id="transactionManagerSqlserver"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager"
p:dataSource-ref="sqlServerDataSource" /> <bean id="transactionManagerMysql"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager"
p:dataSource-ref="mySqlDataSource" /> <tx:annotation-driven transaction-manager="transactionManagerSqlserver" />
<tx:annotation-driven transaction-manager="transactionManagerMysql" /> </beans>
Druid中配置双数据库的更多相关文章
- 【Spring】如何在单个Boot应用中配置多数据库?
原创 BOOT 为什么需要多数据库? 默认情况下,Spring Boot使用的是单数据库配置(通过spring.datasource.*配置具体数据库连接信息).对于绝大多数Spring Boot应用 ...
- linux中配置双网卡的目的?如何实现双网卡绑定,以实现负载均衡?
配置双网卡的目的:========================== 1.你想做路由器,网关 2.实现冗余 3.负载均衡 linux 主机安装双网卡,共享一个IP地址,对外提供访问,实际 同 ...
- tomcat中配置jndi数据库源
tomcat添加依赖 lib目录下添加依赖mysql-connector-java-8.0.16 配置数据源 介绍两种方法:tomcat中配置或web应用中配置 tomcat/conf/context ...
- 在 vue cli3 的项目中配置双服务,模拟 ajax 分页请求
最近安装了下vue cli3版本,与 cli 2 相比,文件少了,以前配置方法也不管用了.demo 中的大量的数据,需要做成 ajax 请求的方式来展示数据,因此,需要启动两个服务,一个用作前端请求, ...
- 如何在Django中配置MySQL数据库
直接上图 在项目中直接找到settings 文件 第一步 原始Django自带数据库 第二步将配置改成MySQL的数据 第三步 在__init__文件中告知Django使用MySQL数据 ...
- 在python中配置MySQL数据库
MySQL数据库(1) 尽管用文件形式将数据保存到磁盘,已经是一种不错的方式.但是,人们还是发明了更具有格式化特点,并且写入和读取更快速便捷的东西——数据库(如果阅读港台的资料,它们称之为“资料库”) ...
- 阿里druid数据源配置及数据库密码加密
注意: 1.阿里默认只对用户密码解密 2.druid 1.0.16版本及以上的解密时需要同时配置publicKey 一.生成密文密码 1 前提:已经配置了jdk环境 1.生成密文密码需要准备druid ...
- Django 中配置MySQL数据库
在Django的项目中会默认使用sqlite的数据库 配置MySQL需要在setting.py 里加入以下设置: 配置数据库 DATABASES = { 'default': { 'ENGINE': ...
- vs2013中配置SQLite数据库
转载:https://maplefan.com/index.php/2019/08/14/visual-studio-2013%e9%85%8d%e7%bd%aesqlite3%e7%9a%84%e6 ...
随机推荐
- log4j-over-slf4j和slf4j-log4j12冲突问题解决
解决办法: 两个jar包会循环引用导致内存溢出.解决的办法就是将两个jar包其中一个的依赖移除掉
- vn.trader的Ubuntu运行环境搭建教程
作者:量衍投资 转载请注明来源:维恩的派(www.vnpie.com) 准备Ubuntu 建议使用一个新安装干净的Ubuntu环境(如果你一定要使用老环境也行,万一不幸掉坑后再回到这步就好),我这里使 ...
- python之format函数
自python2.6开始,新增了一种格式化字符串的函数str.format(),可谓威力十足.那么,他跟之前的%型格式化字符串相比,有什么优越的存在呢?让我们来揭开它羞答答的面纱. 语法 它通过{}和 ...
- php商品对比功能代码分享
商品对比调用的JS文件(包含了商品对比框浮动JS): /*浮动窗口*/ (function(){ var n=10; var obj=document.getElementById(&qu ...
- http请求返回响应码及意义
http 响应码及意义 HTTP状态码(HTTP Status Code)是用以表示网页服务器HTTP响应状态的3位数字代码.它由 RFC 2616 规范定义的,并得到RFC 2518.RFC 281 ...
- 【git】之使用shell脚本提交代码
为减少提交步骤,防止提交错误,使用Shell脚本进行git提交不失一件好事 #!/bin/sh # @author Hubal # @Email Hubal@123.com # @createBy - ...
- Camp 前三日简单总结
1.#include <bits/stdc++.h> 后面别再忘了写 using namespace std; 2.在#include <bits/stdc++.h> 中 可以 ...
- webview之学习文章(待续)
webview与js交互: Tencent/VasSonic(缓存优化方案) lzyzsd/JsBridge: pengwei1024/JsBridge: -----webview的框架 TheFin ...
- SpringBoot 配置文件 中文乱码
本方案,支持springboot 很简单 在配置文件中不写中文,写中文的ascll码 直接百度在线转ASCII,用工具 把中文转ASCII码==>\u628a\u4e2d\u6587\u8f6c ...
- hdfs知识点《转》
HDFS知识点总结 学习完Hadoop权威指南有一段时间了,现在再回顾和总结一下HDFS的知识点. 1.HDFS的设计 HDFS是什么:HDFS即Hadoop分布式文件系统(Hadoop Dist ...