• springboot-配置多数据源之番外篇(分包实现)


    场景:

    随着业务发展,系统连接多数据库成为常态,继前面AOP的实现方式之后,这里记录一下分包实现的方式。

    实现:

     1.pom.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <parent>
            <groupId>com.mumu</groupId>
            <artifactId>springboot-mumu</artifactId>
            <version>1.0-SNAPSHOT</version>
        </parent>
        <artifactId>mumu-web</artifactId>
    
        <dependencies>
            <!-- web -->
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>
            </dependency>
            <!-- aop -->
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-aop</artifactId>
            </dependency>
            <!-- mysql -->
            <dependency>
                <groupId>mysql</groupId>
                <artifactId>mysql-connector-java</artifactId>
                <scope>runtime</scope>
            </dependency>
            <!-- sqlserver -->
            <dependency>
                <groupId>com.microsoft.sqlserver</groupId>
                <artifactId>mssql-jdbc</artifactId>
                <scope>runtime</scope>
            </dependency>
            <!-- mybatis-plus -->
            <dependency>
                <groupId>com.baomidou</groupId>
                <artifactId>mybatis-plus-boot-starter</artifactId>
                <version>3.0.5</version>
            </dependency>
    
        </dependencies>
    
        <build>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                </plugin>
            </plugins>
        </build>
    
    </project>

    2.配置文件

    server:
      port: 9587
    spring:
      datasource:
        hikari:
          master:
            driverClassName: com.mysql.cj.jdbc.Driver
            jdbcUrl: jdbc:mysql://127.0.0.1:3306/boltloan?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=utf8
            username: root
            password: 123456
          slave:
            driverClassName: com.microsoft.sqlserver.jdbc.SQLServerDriver
            jdbcUrl: jdbc:sqlserver://127.0.0.1:1433;DatabaseName=TestDB
            username: SA
            password: <1234567890@Passw0rd>
    #mybatis-plus
    mybatis-plus:
      type-aliases-package: com.mumu.model
      mapper-locations: classpath:/mapper/**/*.xml
      configuration:
        jdbc-type-for-null: null
        map-underscore-to-camel-case: true
        cache-enabled: false
      global-config:
        db-config:
          id-type: auto
          field-strategy: not_empty

    3.数据源配置类

    采用注解的方式:每种数据源,使用一个对应 注解!

    敬请期待...

  • 相关阅读:
    Trie树与AC自动机
    学习强国答题小程序
    小程序如何引导添加个人微信号
    成语答题赚小程序里面涉及到金额的小数计算问题
    答题小程序v2.0
    活动抽奖小程序
    抽奖小程序分享
    抽奖小程序结果页设计
    抽奖小程序数据库设计
    答题活动小程序复盘记录
  • 原文地址:https://www.cnblogs.com/kobe-lin/p/11987519.html
Copyright © 2020-2023  润新知