美文网首页
SpringBoot + Mybatis 配置多数据源的一种方法

SpringBoot + Mybatis 配置多数据源的一种方法

作者: KBOCBRE | 来源:发表于2019-04-17 21:20 被阅读0次
    上图对应的配置

    非主数据源在使用Spring的事务注解使用事务时,要指明所用的事务配置名称


    事务配置 指明使用的事务配置

    yml文件多个数据源配置的方式

    spring:
      datasource:
        db1:
          username: root
          password: 123456
          # spring2.0此处为jdbc-url
          jdbc-url: jdbc:mysql://127.0.0.1:3306/onlinetestsystem?autoReconnect=true&useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai
          type: com.alibaba.druid.pool.DruidDataSource
          druid:
            #连接池配置
            filters: stat,wall
            maxActive: 20
            initialSize: 1
            maxWait: 60000
            minIdle: 1
            timeBetweenEvictionRunsMillis: 60000
            minEvictableIdleTimeMillis: 300000
            validationQuery: select 'x'
            testWhileIdle: true
            testOnBorrow: false
            testOnReturn: false
            poolPreparedStatements: true
            maxOpenPreparedStatements: 20
            connection-properties: druid.stat.merggSql=ture;druid.stat.slowSqlMillis=5000
            # WebStatFilter配置
            web-stat-filter:
              enabled: true
              #        url-pattern:
              exclusions: "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*"
            #        session-stat-enable:
            #        session-stat-max-count:
            #        principal-session-name:
            #        principal-cookie-name:
            #        profile-enable:
            stat-view-servlet:
              enabled: true
              #        url-pattern:
              #        reset-enable:
              login-username: admin
              login-password: admin
        db2:
          username: root
          password:
          # spring2.0此处为jdbc-url
          jdbc-url: jdbc:mysql://192.168.0.122:3306/jol?autoReconnect=true&useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai
          type: com.alibaba.druid.pool.DruidDataSource
          druid:
            #连接池配置
            filters: stat,wall
            maxActive: 20
            initialSize: 1
            maxWait: 60000
            minIdle: 1
            timeBetweenEvictionRunsMillis: 60000
            minEvictableIdleTimeMillis: 300000
            validationQuery: select 'x'
            testWhileIdle: true
            testOnBorrow: false
            testOnReturn: false
            poolPreparedStatements: true
            maxOpenPreparedStatements: 20
            connection-properties: druid.stat.merggSql=ture;druid.stat.slowSqlMillis=5000
            # WebStatFilter配置
            web-stat-filter:
              enabled: true
              #        url-pattern:
              exclusions: "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*"
            #        session-stat-enable:
            #        session-stat-max-count:
            #        principal-session-name:
            #        principal-cookie-name:
            #        profile-enable:
            stat-view-servlet:
              enabled: true
              #        url-pattern:
              #        reset-enable:
              login-username: admin
              login-password: admin
      thymeleaf:
        cache: false
      jackson:
        date-format: yyyy-MM-dd HH:mm:ss
        time-zone: GMT+8
    
    
    server:
      port: 9999
    
    
    logging:
      config: classpath:config/logback-spring.xml
    
    logging.level.org.springframework.boot.autoconfigure: ERROR
    

    相关文章

      网友评论

          本文标题:SpringBoot + Mybatis 配置多数据源的一种方法

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