maven依赖都整上
application.yml
server:
# 端口号
port: 8080
spring:
# 数据源配置
datasource:
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://localhost:3306/spring-dev
username: root
password: 123456
# Druid连接池配置
type: com.alibaba.druid.pool.DruidDataSource
# 初始化
initialSize: 3
# 最大
maxActive: 20
# 最小
minIdle: 3
# 最大连接等待超时时间
maxWait: 60000
# 打开PSCache,并且指定每个连接PSCache的大小
poolPreparedStatements: true
maxPoolPreparedStatementPerConnectionSize: 20
validationQuery: select 'x'
testWhileIdle: true
testOnBorrow: false
testOnReturn: false
# 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
timeBetweenEvictionRunsMillis: 60000
# 配置一个连接在池中最小生存的时间,单位是毫秒
minEvictableIdleTimeMillis: 300000
# 配置监控统计拦截的filters,去掉后监控界面sql将无法统计,'wall'用于防火墙
filters: stat, wall, log4j
# spring data jpa配置
jpa:
hibernate:
# 实体类有更新时,数据库表更新
ddl-auto: update
show-sql: true
format_sql: true
database-platform: org.hibernate.dialect.MySQL5InnoDBDialect
http:
# 过滤字符编码
encoding:
charset: UTF-8
enabled: true
force: true
druidconfig
@Configuration
public class DruidConfig {
@Bean
public ServletRegistrationBean statViewServlet() {
// 创建servlet注册实体
ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean(new StatViewServlet(),
"/druid/*");
// 设置ip白名单
servletRegistrationBean.addInitParameter("allow", "127.0.0.1");
// 设置ip黑名单,如果allow与deny共同存在时,deny优先于allow
servletRegistrationBean.addInitParameter("deny", "192.168.0.1");
// 设置控制台管理用户
servletRegistrationBean.addInitParameter("loginUsername", "admin");
servletRegistrationBean.addInitParameter("loginPassword", "123456");
// 是否可以重置数据
servletRegistrationBean.addInitParameter("resetEnable", "false");
return servletRegistrationBean;
}
@Bean
public FilterRegistrationBean statFilter() {
// 创建过滤器
FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean(new WebStatFilter());
// 设置过滤器过滤路径
filterRegistrationBean.addUrlPatterns("/*");
// 忽略过滤的形式
filterRegistrationBean.addInitParameter("exclusions", "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*");
return filterRegistrationBean;
}
}