背景:最近项目需求需要同时查询MySQL和Oracle的数据,项目已经上线,总结一下,以备后续查看(该文档并不是完整的项目)。
项目基于gradle管理的标准的Web MVC架构:
build.gradle
group 'com.data.mult'
version '1.0-SNAPSHOT'
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'application'
mainClassName = 'com.data.mult.MultDataSourceApplication'
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenLocal()
maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
maven { url "http://repo.maven.apache.org/maven2" }
mavenCentral()
}
dependencies {
compile group: 'com.alibaba', name: 'fastjson', version: '1.2.60'
compile('org.springframework.boot:spring-boot-starter-web:2.1.5.RELEASE') {
exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging'
}
compile group: 'org.springframework.boot', name: 'spring-boot-starter-log4j2', version: '2.1.5.RELEASE'
compile('org.mybatis.spring.boot:mybatis-spring-boot-starter:2.0.1') {
exclude group: 'org.springframework.boot', module: 'spring-boot-starter'
}
compile group: 'com.oracle.jdbc', name: 'ojdbc6', version: '11.2.0.4.0'
compile group: "mysql", name: "mysql-connector-java", version: "8.0.11"
}
application.properties
#mybatis的配置文件路径
mybatis.config-locations=classpath:mybatis/mybatis-config.xml
#mybatis的mapper映射文件地址路径
mybatis.mapper-locations=classpath:mybatis/mapper/*.xml
#mysql库1的配置
spring.datasource.primary.driverClassName=com.mysql.cj.jdbc.Driver
spring.datasource.primary.jdbc-url=jdbc:mysql://localhost:3306/lwca?characterEncoding=utf8
spring.datasource.p