SpringBoot整合mybatis-plus+druid多数据源+Swagger2

项目地址:https://github.com/ZZD3627/my-multiple002.git
此yml为:https://github.com/ZZD3627/my-multiple002.git项目的配置文件【配置文件漏传了,需要整合进代码中】

# server
server:
  port: 8080
#  servlet:
#    context-path: /dynamicdatasource


# spring
spring:
  datasource:
    dynamic:
      primary: master #设置默认的数据源或者数据源组,默认值即为master
      strict: false #严格匹配数据源,默认false. true未匹配到指定数据源时抛异常,false使用默认数据源
      datasource:
        master: #可以配置各种数据源
          url: jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=GMT%2B8&allowMultiQueries=true&autoReconnect=true
          username: root
          password: ******
          driver-class-name: com.mysql.cj.jdbc.Driver
        slave:
          url: jdbc:mysql://localhost:3306/student?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=GMT%2B8&allowMultiQueries=true&autoReconnect=true
          username: root
          password: ******
          driver-class-name: com.mysql.cj.jdbc.Driver
    druid:
      # 连接池配置
      # 配置初始化大小、最小、最大
      initial-size: 5
      max-active: 200
      min-idle: 5
      # 连接超时时间
      max-wait: 6000
      # 间隔多久进行一次检测,检测需要关闭的空闲连接,单位是毫秒
      time-between-eviction-runs-millis: 60000
      # 一个连接在连接池中最小的生存时间,单位是毫秒
      min-evictable-idle-time-millis: 120000
      # 用来检测连接是否有效的sql,要求是一个查询语句。 如果validationQuery为null,testOnBorrow、testOnReturn、 testWhileIdle都不会其作用。
      validation-query: SELECT 1
      # 当从连接池借用连接时,是否测试该连接
      test-on-borrow: false
      # 在连接归还到连接池时是否测试该连接
      test-on-return: false
      # 当连接空闲时,是否执行连接测试
      test-while-idle: true
      # 是否缓存preparedStatement,也就是PSCache。 PSCache对支持游标的数据库性能提升巨大,比如说oracle。 在mysql5.5以下的版本中没有PSCache功能,建议关闭掉
      pool-prepared-statements: true
      # 要启用PSCache,必须配置大于0,当大于0时, poolPreparedStatements自动触发修改为true。 在Druid中,不会存在Oracle下PSCache占用内存过多的问题, 可以把这个数值配置大一些,比如说100
      max-pool-prepared-statement-per-connection-size: 100
      # 合并多个DruidDataSource的监控数据
      use-global-data-source-stat: true
      # 配置监控统计拦截的filters,去掉后监控界面sql无法统计,'wall'用于防火墙
      filter:
        # 慢SQL记录(sql语句执行时间超过某个界限就记录下来)
        stat:
          log-slow-sql: true
          slow-sql-millis: 2000
      #        wall:
      #          config:
      #            none-base-statement-allow: true
      #            multi-statement-allow: true
      # 本来有防火墙的过滤器的,但批量更新总是过不去,就去掉了,加防火墙怎么实现批量更新?还没解决
      filters: stat
      #  监控配置
      # WebStatFilter配置
      web-stat-filter:
        # 是否开启web-jdbc监控 默认是false
        enabled: true
        # 是否开启单个监控url调用的sql列表 默认开启
        profile-enable: true
        url-pattern: /*
        exclusions: /druid/*,*.gif,*.png,*.jpg,*.html,*.js,*.css,*.ico
        # 是否开启session统计 默认false
        session-stat-enable: true
        # 设置session统计的最大值 默认是1000
        session-stat-max-count: 1000

      # StatViewServlet配置
      stat-view-servlet:
        # 是否开启druid的数据统计界面 默认false
        enabled: true
        url-pattern: /druid/*
        #  登录监控界面的用户名以及密码,登录url为 IP:port/druid
        login-username: druid
        login-password: 123
        allow:
        deny:
        #  HTML页面上的“Reset All”功能
        reset-enable: true


# mybatis
mybatis-plus:
  type-aliases-package: com.example.demo.entity
  # 指定mybatis映射文件的位置
  mapper-locations: classpath:mapper/*.xml
  configuration:
    # 开启驼峰命名转换(开启后需要注意字段写法,不然返回值为null)
    map-underscore-to-camel-case: true
    # 配置mybatis日志输出
    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
  global-config:
    db-config:
      id-type: AUTO

只是简单的整合好了,还没有时间来好好的对每一部分,分别处理,待后期有时间会对每一部分,分别解析。不喜勿骂。

参考:
https://cloud.tencent.com/developer/article/1862325
https://blog.csdn.net/qq_40205116/article/details/105200104
https://cloud.tencent.com/developer/article/1798112
https://www.cnblogs.com/qdhxhz/p/10192041.html
https://www.jianshu.com/p/3daab1b74044

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值