Spring Boot2.x the Druid connection pool configuration [accompanying monitoring]

Father dependent [Spring Boot 2.1.x version]

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.1.1.RELEASE</version>
</parent>

 

Mainly dependent [3]

<! - dependent Druid pools of connections Spring Boot binding -> 
< dependency > 
    < the groupId > com.alibaba </ the groupId > 
    < the artifactId > Druid-Spring-Boot-Starter </ the artifactId > 
    < Version > 1.1.10 < / Version > 
</ dependency > 
<-! the Spring Web dependent on the Boot, certain components in the Druid is still dependent on Web component, after all, is the need to monitor the displayed page -> 
< dependency > 
    < groupId > org.springframework.boot </ the groupId >
    <the artifactId > Spring-Boot-Starter-Web </ the artifactId > 
</ dependency > 
<-! MySQL version 8.0+] [depend, of course, spring boot may be connected to other relational databases, but this is not the code other examples -> 
< dependency > 
    < the groupId > MySQL </ the groupId > 
    < the artifactId > MySQL-Connector-Java </ the artifactId > 
</ dependency >

 

Spring Boot Configuration Profiles

#datasource base config
spring.datasource.username = database user name
spring.datasource.password = database password
spring.datasource.url = jdbc: MySQL: // Database IP:? port / database name = useUnicode to 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 monitor sites
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

 

The basic premise of the test:

Plus some basic operation of the database operations controller,
and then access the project:  HTTP: // ip : port / druid
and enter the root user and password to access the configuration of the above

Annex 1: the item original dependency pom [Test Examples] containing simple

<?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.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.1.RELEASE</version>
    </parent>
    <groupId>com.xcky</groupId>
    <artifactId>shop-druid</artifactId>
    <version>0.1</version>
    <name>shop-druid</name>
    <properties>
        <java.version>1.8</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid-spring-boot-starter</artifactId>
            <version>1.1.10</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
        </dependency>
        
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <scope>provided</scope>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>

 

Annex 2: Demonstration of the item code and a sample code

Example: http://lb-chen.cn:9005/druid  user and password are root

If the monitoring station does not have any data, please visit the following address again to refresh the console

Guess you like

Origin www.cnblogs.com/lywJ/p/11165505.html