DruidConfiguration.java 文件
/**
* Copyright (C), 2019-2019, XXX有限公司
* FileName: DruidConfiguration
* Author: Fish
* Date: 2019/5/4 12:25
* Description:
* History:
*<author><time><version><desc>
* 作者姓名 修改时间 版本号 描述
*/
packagecom.yuqiyu.lessonthree;
importcom.alibaba.druid.support.http.StatViewServlet;
importcom.alibaba.druid.support.http.WebStatFilter;
importorg.springframework.boot.web.servlet.FilterRegistrationBean;
importorg.springframework.boot.web.servlet.ServletRegistrationBean;
importorg.springframework.context.annotation.Bean;
importorg.springframework.context.annotation.Configuration;
@Configuration
public classDruidConfiguration {
@Bean
publicServletRegistrationBean statViewServlet(){
//创建servlet注册实体
ServletRegistrationBean servletRegistrationBean =newServletRegistrationBean(newStatViewServlet(),"/druid/*");
//设置ip白名单
servletRegistrationBean.addInitParameter("allow","127.0.0.1");
//设置ip黑名单,如果allow与deny共同存在时,deny优先于allow
servletRegistrationBean.addInitParameter("deny","192.168.0.19");
//设置控制台管理用户
servletRegistrationBean.addInitParameter("loginUsername","druid");
servletRegistrationBean.addInitParameter("loginPassword","123456");
//是否可以重置数据
servletRegistrationBean.addInitParameter("resetEnable","false");
returnservletRegistrationBean;
}
@Bean
publicFilterRegistrationBean statFilter(){
//创建过滤器
FilterRegistrationBean filterRegistrationBean =newFilterRegistrationBean(newWebStatFilter());
//设置过滤器过滤路径
filterRegistrationBean.addUrlPatterns("/*");
//忽略过滤的形式
filterRegistrationBean.addInitParameter("exclusions","*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*");
returnfilterRegistrationBean;
}
}
application.yml 文件
spring:
datasource:
type: com.alibaba.druid.pool.DruidDataSource
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://127.0.0.1:3306/dbgirl?characterEncoding=utf8
username: root
password: 你的mysql密码
#最大活跃数
maxActive: 20
#初始化数量
initialSize: 1
#最大连接等待超时时间
maxWait: 60000
#打开PSCache,并且指定每个连接PSCache的大小
poolPreparedStatements: true
maxPoolPreparedStatementPerConnectionSize: 20
#通过connectionProperties属性来打开mergeSql功能;慢SQL记录
#connectionProperties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000
minIdle: 1
timeBetweenEvictionRunsMillis: 60000
minEvictableIdleTimeMillis: 300000
validationQuery: select 1 from dual
testWhileIdle: true
testOnBorrow: false
testOnReturn: false
#配置监控统计拦截的filters,去掉后监控界面sql将无法统计,'wall'用于防火墙
filters: stat, wall, log4j
jpa:
properties:
hibernate:
show_sql: true
format_sql: true