前言申明
springBoot配置双数据源主要是配置类的书写和配置文件的书写,本文采用yml的形式进行配置,mapper和pojo两个个数据库都共用一个路径,dao层分开书写,各自配置文件中直接配置各自扫描路径即可。本文只讲解如何配置双数据源,如需配置单数据源的童鞋,可参看该链接:https://www.cnblogs.com/zblwyj/p/10668803.html
一、导入jar包
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.0.0</version>
</dependency<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.1.9</version>
</dependency>
<!-- sqlite3驱动包 -->
<dependency>
<groupId>org.xerial</groupId>
<artifactId>sqlite-jdbc</artifactId>
</dependency>
二、书写配置文件
View Code
# Tomcat server: tomcat: uri-encoding: UTF-8 max-threads: 1000 min-spare-threads: 30 port: 8088 #spring spring: # 指定静态资源的路径 resources: static-locations: classpath:/static/,classpath:/views/,file:${web.upload},file:${web.ueditorUpload} # 数据源一 datasource: master: jdbc-url: jdbc:sqlite:D:/java/xy.db # jdbc-url: jdbc:sqlite:/usr/java/myfile/xy.db driver-class-name: org.sqlite.JDBC username: password: #数据源二 other: driver-class-name: org.sqlite.JDBC # 方式一: 引用外部文件 jdbc-url: jdbc:sqlite:D:/system.db username: password: # Mybatis配置 #mybatis: # mapperLocations: classpath:mapper/**/*.xml # configLocation: classpath:/mybatis.xml # sql打印 logging: level: debug level.com.xuanyin: debug # path: logs/ # file: admin.log