最近需要配置springcloud多数据源, 既有mysql又有sqlserver,详细配置如下
1、配置bootstrap.yml
spring:
datasource:
ds1:
driver-class-name: com.mysql.cj.jdbc.Driver
jdbc-url: jdbc:mysql://mysql地址:3306/数据库名?useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT%2B8
username: root
password: 密码
type: com.alibaba.druid.pool.DruidDataSource
ds2:
driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver
jdbc-url: jdbc:sqlserver://sqlserver地址:1433;DatabaseName=数据库名
username: 用户名
password: 密码
type: com.alibaba.druid.pool.DruidDataSource
2、配置ds1的config文件
package com.apex.config;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.SqlSessionTemplate;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.