Reproduced please indicate the original address: https://www.cnblogs.com/ygj0930/p/11280540.html
A: DRUID connection pool Profile
Ali produced "Born to monitor" the database connection pool, functionality, performance, scalability, more than other database connection pool, while adding log monitoring, can be a good monitor implementation DB connection pool and SQL. And the only one to solve the problem of leakage PSCache connected connection pool.
II: introducing bag or jar add dependencies
<dependency> <groupId>com.alibaba</groupId> <artifactId>druid</artifactId> <version>1.0.18</version> </dependency>
III: Configure Connection Pool
1: Create a configuration file to configure druid.properties
url jdbcUrl connection to the database: MySQL: jdbc: MySQL: // localhost: 3306 / the Test username username database password password database driverClassName driver class name. The url automatic identification, which can be equipped with an unworthy, if not based on the configuration druid automatically identify dbType url, then select the appropriate driverClassName (recommended configuration) to establish the number of physical connections during initialization initialSize. Initialization occurs in displaying calling the init method, or the first time the getConnection for maxActive the maximum number of connection pools maxIdle no longer used, the configuration did not effect the minimum number of connection pools minIdle when connected maxWait obtain the maximum waiting time, in milliseconds.
2: SpringBoot project directly to the configuration in application.properties
Database access configuration # # primary data source, the default spring.datasource.type = com.alibaba.druid.pool.DruidDataSource spring.datasource.driver - class -name = com.mysql.jdbc.Driver spring.datasource.url = JDBC : MySQL: // localhost: 3306 / Test spring.datasource.username = the root spring.datasource.password = 123456 # added to set the following connection pool, is applied to all of the above data sources # initial size, minimum, maximum spring.datasource .initialSize =. 5 spring.datasource.minIdle =. 5 spring.datasource.maxActive = 20 is # configuration acquiring connection waiting timeout time spring.datasource.maxWait = 60000 # Intervals the frequency of such detection, an idle connection is detected to be closed, in milliseconds spring.datasource.timeBetweenEvictionRunsMillis = 60000 # arranged a minimum connection time survival pool milliseconds spring.datasource.minEvictableIdleTimeMillis = 300000 Spring. datasource.validationQuery = the SELECT. 1 the FROM the DUAL spring.datasource.testWhileIdle = to true spring.datasource.testOnBorrow = to false spring.datasource.testOnReturn = to false # open PSCache, and specifies the size of each connection PSCache spring.datasource.poolPreparedStatements = to true Spring .datasource.maxPoolPreparedStatementPerConnectionSize = 20 # configure monitoring statistics intercepted filters, after removing the monitoring interface sql not statistics, 'Wall'Firewalls spring.datasource.filters = STAT, Wall, log4j # mergeSql opened by connectProperties property function; slow SQL record spring.datasource.connectionProperties = = druid.stat.mergeSql to true ; druid.stat.slowSqlMillis = 5000 # merge multiple monitoring data of a DruidDataSource # spring.datasource.useGlobalDataSourceStat = to true
Four: the definition of DBUtils Tools
Initializing the connection pool with connection profiles, and a method for obtaining a series connection defines a method of operating a database.
Five: Use the DAO layer
dbutil database operations.
Six: Druid monitoring using statistical functions
https://github.com/alibaba/druid/wiki/%E9%85%8D%E7%BD%AE_StatFilter
Seven: Druid page using the built-in monitor
https://github.com/alibaba/druid/wiki/%E9%85%8D%E7%BD%AE_StatViewServlet%E9%85%8D%E7%BD%AE
Eight: Configure SQL injection defense
https://github.com/alibaba/druid/wiki/%E9%85%8D%E7%BD%AE-wallfilter
Nine: SQL execution logging configuration
https://github.com/alibaba/druid/wiki/%E9%85%8D%E7%BD%AE_LogFilter
Ten: Connection Leak Monitoring
https://github.com/alibaba/druid/wiki/%E8%BF%9E%E6%8E%A5%E6%B3%84%E6%BC%8F%E7%9B%91%E6%B5%8B
Eleven: PSCache memory footprint issues
https://github.com/alibaba/druid/wiki/Oracle%E6%95%B0%E6%8D%AE%E5%BA%93%E4%B8%8BPreparedStatementCache%E5%86%85%E5%AD%98%E9%97%AE%E9%A2%98%E8%A7%A3%E5%86%B3%E6%96%B9%E6%A1%88
12: Slow implementation of SQL record
https://github.com/alibaba/druid/wiki/%E9%85%8D%E7%BD%AE_StatFilter
Thirteen: Database Password Encryption
https://github.com/alibaba/druid/wiki/%E4%BD%BF%E7%94%A8ConfigFilter
Fourteen: SpringBoot configured Druid
https://github.com/alibaba/druid/tree/master/druid-spring-boot-starter