pom文件引入
<!--阿里数据库连接池 -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>1.1.14</version>
</dependency>
通过如下注解方式配置druid
server: port: 8083 # 服务器的HTTP端口,默认为8083 spring: autoconfigure: exclude: # 多数据源环境下必须排除掉 DataSourceAutoConfiguration,否则会导致循环依赖报错 - org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration datasource: # schema: #自动数据库建表 # -classpath: master: driver-class-name: com.mysql.cj.jdbc.Driver url: jdbc:mysql://localhost:3306/ctms?serverTimezone=UTC&useUnicode=true&characterEncoding=utf-8&useSSL=false username: root password: root slaver1: driver-class-name: com.mysql.cj.jdbc.Driver url: jdbc:mysql://localhost:3306/ctms2?serverTimezone=UTC&useUnicode=true&characterEncoding=utf-8&useSSL=false username: root password: root slaver2: driver-class-name: com.mysql.cj.jdbc.Driver url: jdbc:mysql://localhost:3306/ctms_kt?serverTimezone=UTC&useUnicode=true&characterEncoding=utf-8&useSSL=false username: root password: root other: driver-class-name: com.mysql.cj.jdbc.Driver url: jdbc:mysql://localhost:3306/ctms_fangen?serverTimezone=UTC&useUnicode=true&characterEncoding=utf-8&useSSL=false username: root password: root type: com.alibaba.druid.pool.DruidDataSource name: druidDataSource druid: # druid配置 initial-size: 5 # 连接池配置,初始化大小,最小,最大 min-idle: 5 max-active: 20 max-wait: 60000 #连接等待超时时间 time-between-eviction-runs-millis: 60000 # 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位毫秒 min-evictable-idle-time-millis: 300000 #配置连接在池中的最小生存时间 validation-query: SELECT 1 from dual test-while-idle: true test-on-borrow: false test-on-return: false pool-prepared-statements: true #打开PSCache,并且指定每个连接上PSCache的大小 max-pool-prepared-statement-per-connection-size: 20 max-create-task-count: 20 # 通过 connection-properties 属性打开 mergeSql 功能;慢 SQL 记录 # connection-properties: druid.stat.mergeSql\\=true;druid.stat.slowSqlMillis\\=5000 # 通过 connection-properties 属性打开 mergeSql 功能;慢 SQL 记录 filters: #配置监控统计拦截的filters,去掉后监控界面sql无法统计,\'wall\'用于防火墙 -stat -log4j -slf4j -log4j2 -wall stat-view-servlet: enabled: true # 启用StatViewServlet url-pattern: /druid/* # 访问内置监控页面的路径,内置监控页面的首页是/druid/index.html reset-enable: false # 不允许清空统计数据,重新计算 login-password: admin # 配置监控页面访问账户密码 login-username: admin # 允许访问的地址,如果allow没有配置或者为空,则允许所有访问 allow: 127.0.0.1 deny: # 拒绝访问的地址,deny优先于allow,如果在deny列表中,就算在allow列表中,也会被拒绝 filter: #配置监控统计拦截的filters,去掉后监控界面sql无法统计,\'wall\'用于防火墙 stat: enabled: true log-slow-sql: true #慢sql记录 slow-sql-millis: 1000 merge-sql: true wall: config: multi-statement-allow: true #Spring监控AOP切入点,如x.y.z.service.*,配置多个英文逗号分隔 # aop-patterns: com.spring.boot.druid.service.* jpa: open-in-view: false logging: #日志 level: org.springframework.jdbc.core.JdbcTemplate: DEBUG
来源:https://www.cnblogs.com/limumu/p/16449509.html
本站部分图文来源于网络,如有侵权请联系删除。