JAVA (spring boot) 多数据源配置

2020-08-04  本文已影响0人  欢欢011

1.在启动文件加上

@SpringBootApplication(scanBasePackages = "cn.medbanks",exclude = { DruidDataSourceAutoConfigure.class }

2.在maven文件中添加多数据源依赖

<dependency>

    <groupId>com.baomidou</groupId>

    <artifactId>dynamic-datasource-spring-boot-starter</artifactId>

    <version>3.0.0</version>

</dependency>

3.在bootstrap-dev.yml中添加

#数据库配置

  datasource:

    dynamic:

      primary: master

      strict: false

      datasource:

        master:

          url: jdbc:mysql://url?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8

          username: root

          password: 123456

          driver-class-name: com.mysql.jdbc.Driver

        data_warehouse:

          url: jdbc:mysql://url?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8

          username: root   

          password: 123456

          driver-class-name: com.mysql.jdbc.Driver

上一篇下一篇

猜你喜欢

热点阅读