标签:没有 encoding utf8 dstat css artifact merge 需要 yam
导入依赖
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.1.21</version>
</dependency>
配置数据库以及数据源的相关属性
spring:
datasource:
password: root
username: root
url: jdbc:mysql://127.0.0.1:3307/db_book_system?characterEncoding=utf8&useSSL=false&serverTimezone=UTC&rewriteBatchedStatements=true
driver-class-name: com.mysql.jdbc.Driver
type: com.alibaba.druid.pool.DruidDataSource
# 连接池的配置信息
# 初始化大小,最小,最大
initial-size: 5
min-idle: 5
maxActive: 20
# 配置获取连接等待超时的时间
maxWait: 60000
# 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
timeBetweenEvictionRunsMillis: 60000
# 配置一个连接在池中最小生存的时间,单位是毫秒
minEvictableIdleTimeMillis: 300000
validationQuery: SELECT 1
testWhileIdle: true
testOnBorrow: false
testOnReturn: false
# 打开PSCache,并且指定每个连接上PSCache的大小
poolPreparedStatements: true
maxPoolPreparedStatementPerConnectionSize: 20
# 配置监控统计拦截的filters,去掉后监控界面sql无法统计,'wall'用于防火墙
filters: stat,wall,slf4j
# 通过connectProperties属性来打开mergeSql功能;慢SQL记录
connectionProperties: druid.stat.mergeSql\=true;druid.stat.slowSqlMillis\=5000
# 配置DruidStatFilter
web-stat-filter:
enabled: true
url-pattern: "/*"
exclusions: "*.js,*.gif,*.jpg,*.bmp,*.png,*.css,*.ico,/druid/*"
# 配置DruidStatViewServlet
stat-view-servlet:
url-pattern: "/druid/*"
# IP白名单(没有配置或者为空,则允许所有访问)
allow: 127.0.0.1
# IP黑名单 (存在共同时,deny优先于allow)
deny:
# 禁用HTML页面上的“Reset All”功能
reset-enable: false
# 登录名
login-username: admin
# 登录密码
login-password: 123456
将数据源加入到spring容器中去
@Configuration//声明这是一个配置类,相当于spring配置的一个xxx.xml文件
public class DruidConfig {
//自动映射上面配置以spring.datasource开头的yaml的配置文件
@ConfigurationProperties(prefix = "spring.datasource")
@Bean
public DataSource druidDatasource(){
return new DruidDataSource();
}
//ServletRegistrationBean 相当于web.xml注册了一个servlet(new StatViewServlet())
@Bean
public ServletRegistrationBean statViewServlet(){
ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean(new StatViewServlet(), "/druid/*");
HashMap<String, String> map = new HashMap<>();
//账号密码是固定不变的
map.put("loginUsername","admin");
map.put("loginPassword","123456");
map.put("allow","");
//禁止访问 map.put("user","127.0.0.1");
servletRegistrationBean.setInitParameters(map);
return servletRegistrationBean;
}
//FilterRegistrationBean 相当于web.xml 注册了一个filter(new WebStatFilter())
@Bean
public FilterRegistrationBean webStatFilter(){
FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean();
filterRegistrationBean.setFilter(new WebStatFilter());
HashMap<String, String> map = new HashMap<>();
//不需要过滤的请求
map.put("exclusions","*.js,*.css,/druid/**");
filterRegistrationBean.setInitParameters(map);
return filterRegistrationBean;
}
}
标签:没有 encoding utf8 dstat css artifact merge 需要 yam
原文地址:https://www.cnblogs.com/zhangshiyan/p/12134454.html