美文网首页
JAVA (spring boot) 多数据源配置

JAVA (spring boot) 多数据源配置

作者: 欢欢011 | 来源:发表于2020-08-04 18:05 被阅读0次

    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

    相关文章

      网友评论

          本文标题:JAVA (spring boot) 多数据源配置

          本文链接:https://www.haomeiwen.com/subject/ovvsrktx.html