Spring Boot2.x 的Druid连接池配置[附带监控]
2020-12-13 06:04
标签:nts 数据库密码 ted 基本操作 ali nbsp aop wait select 加上一些基本操作数据库操作的controller, http://lb-chen.cn:9005/user/list Spring Boot2.x 的Druid连接池配置[附带监控] 标签:nts 数据库密码 ted 基本操作 ali nbsp aop wait select 原文地址:https://www.cnblogs.com/lywJ/p/11165505.html父依赖【Spring Boot 2.1.x版本】
parent>
groupId>org.springframework.bootgroupId>
artifactId>spring-boot-starter-parentartifactId>
version>2.1.1.RELEASEversion>
parent>
主要依赖【3个】
dependency>
groupId>com.alibabagroupId>
artifactId>druid-spring-boot-starterartifactId>
version>1.1.10version>
dependency>
dependency>
groupId>org.springframework.bootgroupId>
artifactId>spring-boot-starter-webartifactId>
dependency>
dependency>
groupId>mysqlgroupId>
artifactId>mysql-connector-javaartifactId>
dependency>
Spring Boot配置文件配置
#datasource base config
spring.datasource.username=数据库用户名
spring.datasource.password=数据库密码
spring.datasource.url=jdbc:mysql://数据库IP:端口/数据库名称?useUnicode=true&useSSL=false
#annoated driverClassName,have [cj]
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
#druid pool standard config
spring.datasource.druid.max-active=30
spring.datasource.druid.initial-size=3
spring.datasource.druid.min-idle=3
spring.datasource.druid.max-wait=12000
spring.datasource.druid.time-between-eviction-runs-millis=60000
spring.datasource.druid.min-evictable-idle-time-millis=30000
spring.datasource.druid.pool-prepared-statements=true
spring.datasource.druid.max-open-prepared-statements=30
spring.datasource.druid.validation-query=select 1 from dual
spring.datasource.druid.test-while-idle=true
spring.datasource.druid.test-on-borrow=false
spring.datasource.druid.test-on-return=false
#druid extends config
#druid sql firewall monitor
spring.datasource.druid.filter.wall.enabled=true
#druid sql monitor
spring.datasource.druid.filter.stat.enabled=true
spring.datasource.druid.filter.stat.log-slow-sql=true
spring.datasource.druid.filter.stat.slow-sql-millis=10000
spring.datasource.druid.filter.stat.merge-sql=true
#druid uri monitor
spring.datasource.druid.web-stat-filter.enabled=true
spring.datasource.druid.web-stat-filter.url-pattern=/*
spring.datasource.druid.web-stat-filter.exclusions=*.js,*.gif,*.jpg,*.bmp,*.png,*.css,*.ico,/druid/*
#druid session monitor
spring.datasource.druid.web-stat-filter.session-stat-enable=true
spring.datasource.druid.web-stat-filter.profile-enable=true
#druid spring monitor
spring.datasource.druid.aop-patterns=com.xcky.*
#druid login user config
spring.datasource.druid.stat-view-servlet.login-username=root
spring.datasource.druid.stat-view-servlet.login-password=root
基本测试前提:
然后访问项目: http://ip:端口/druid
然后输入上面配置的用户和密码root即可访问附1:本项目原本的pom依赖【含简单测试例子】
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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
modelVersion>4.0.0modelVersion>
parent>
groupId>org.springframework.bootgroupId>
artifactId>spring-boot-starter-parentartifactId>
version>2.1.1.RELEASEversion>
parent>
groupId>com.xckygroupId>
artifactId>shop-druidartifactId>
version>0.1version>
name>shop-druidname>
properties>
java.version>1.8java.version>
properties>
dependencies>
dependency>
groupId>com.alibabagroupId>
artifactId>druid-spring-boot-starterartifactId>
version>1.1.10version>
dependency>
dependency>
groupId>org.springframework.bootgroupId>
artifactId>spring-boot-starter-webartifactId>
dependency>
dependency>
groupId>mysqlgroupId>
artifactId>mysql-connector-javaartifactId>
dependency>
dependency>
groupId>org.springframework.bootgroupId>
artifactId>spring-boot-starter-data-jpaartifactId>
dependency>
dependency>
groupId>org.projectlombokgroupId>
artifactId>lombokartifactId>
scope>providedscope>
dependency>
dependencies>
build>
plugins>
plugin>
groupId>org.springframework.bootgroupId>
artifactId>spring-boot-maven-pluginartifactId>
plugin>
plugins>
build>
project>
附2:本项目示范代码及代码示例
示例源代码:https://github.com/XiaoCao1434/shop-druid
示例:http://lb-chen.cn:9005/druid 用户和密码都为root
如果监控台没有任何数据,请访问如下地址再刷新控制台即可
文章标题:Spring Boot2.x 的Druid连接池配置[附带监控]
文章链接:http://soscw.com/essay/32379.html