Springboot 整合Druid
2021-04-20 03:34
标签:utc except merge return uid type admin pre mave 导入依赖 配置 导入一个功能,以 log4j 为例 后台监控 Springboot 整合Druid 标签:utc except merge return uid type admin pre mave 原文地址:https://www.cnblogs.com/peng8098/p/java_25.htmlspring:
datasource:
username: admin
password: 8098
# 如果时区报错了,加一个时区的配置:serverTimezone=UTC
url: jdbc:mysql://localhost:3306/mybatis?useUnicode=true&characterEncoding=utf8&useSSL=false
driver-class-name: com.mysql.jdbc.Driver
type: com.alibaba.druid.pool.DruidDataSource
# druid专有配置
initial-size: 5
minIdle: 5
maxActive: 20
maxWait: 60000
timeBetweenEvictionRunsMillis: 60000
minEvictableIdleTimeMillis: 300000
validationQuery: SELECT 1 FROM DUAL
testWhileIdle: true
testOnBorrow: false
testOnReturn: false
poolPreparedStatements: true
#配置监控统计拦载的filters,stat: 监控统计、Log4j: 日志记录、wall:防御sql注入
#如果允许时报错java.lang.ClassNotFoundException: org.apache.Log4j.Priority
#则导入Log4j依赖即可,Maven 地址: https://mvnrepository. com/artifact/Log4j/Log4j
filters: stat,wall,1og4j
maxPoolPreparedStatementPerConnectionSize: 20
useGlobalDataSourceStat: true
connectionProperties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=500
package com.peng.config;
import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.support.http.StatViewServlet;
import com.alibaba.druid.support.http.WebStatFilter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import javax.servlet.Filter;
import javax.sql.DataSource;
import java.util.HashMap;
import java.util.Map;
@Configuration
public class DruidConfig {
@ConfigurationProperties(prefix = "spring.datasource")
@Bean
public DataSource druidDataSource(){
return new DruidDataSource();
}
//后台监控:web.xml,ServletRegis trationBean
//因为SpringBoot内置了servlet容器,所以没有web.xmL
@Bean
public ServletRegistrationBean statViewServlet(){
//固定写法
ServletRegistrationBean
上一篇:Java异常
下一篇:java与c的易混淆区别
文章标题:Springboot 整合Druid
文章链接:http://soscw.com/index.php/essay/76959.html