在项目中当我们需要用到2个不同数据源的数据,我们可以在yml文件里面这样配置
.........
server:
#(端口号)
port: 59006
c3:
datasource:
groups:
#自定义第一个库的连接名
ku1:
pattern: ""
url: jdbc:mysql://连接地址:数据库连接端口号/数据库名字?useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true&useSSL=false
username: 数据库账号
password: 数据库密码
##自定义第二个库的连接名
ku2:
pattern: ""
url: jdbc:mysql://连接地址:数据库连接端口号/数据库名字?useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true&useSSL=false
username: 数据库账号
password: 数据库密码
p6spyEnabled: true
配置好了之后,在service实现impl层调用@DataSourceKey(group = “自定义的库名”)