Springboot中配置druid
pom文件信息:
<!--引入druid数据源-->
<!-- https://mvnrepository.com/artifact/com.alibaba/druid -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.1.18</version>
</dependency>
application.yml文件:
####*****************###
### by咕咕咕 ###
### 数据库配置信息 ###
####***************### # -- -- -- -- -- --
# 配置数据库连接信息
# -- -- -- -- -- --
spring:
datasource:
username: root
password: 123456
url: jdbc:mysql://192.168.31.243:3306/jdbc-data
driver-class-name: com.mysql.cj.jdbc.Driver
type: com.alibaba.druid.pool.DruidDataSource # 设置数据源
# -- -- -- -- -- --
# 使用Druid数据源
# -- -- -- -- -- --
# 配置Druid的其他参数,以下配置必须增加一个配置文件才能有效
# 初始化大小,最小,最大
initialSize: 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,去掉后监控界面sql无法统计,'wall'用于防火墙
filters: stat, wall
# 打开PSCache,并且指定每个连接上PSCache的大小
maxPoolPreparedStatementPerConnectionSize: 20
# 通过connectProperties属性来打开mergeSql功能;慢SQL记录
connectionProperties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=500
# 合并多个DruidDataSource的监控数据
useGlobalDataSourceStat: true
新建config包:
创建DruidConfig.java
package com.zdgd.springbootmybatis.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.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
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.sql.DataSource;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map; /**
* description: DruidConfig <br>
* date: 2019/7/10 20:28 <br>
* author: by咕咕咕 <br>
* version: 1.0 <br>
* 使用Druid数据源
*/
@Configuration
public class DruidConfig { @Bean
@ConfigurationProperties(prefix = "spring.datasource")
public DataSource druid() {
return new DruidDataSource();
} //1、配置一个管理后台的Servlet
@Bean
public ServletRegistrationBean statViewServlet() { //这里做好不要设置为默认的路径!以免被入侵!
ServletRegistrationBean bean = new ServletRegistrationBean(new StatViewServlet(), "/project/druid/*");
System.out.println(bean);
Map<String, String> initParams = new HashMap<>(); initParams.put("loginUsername", "admin");
initParams.put("loginPassword", "bin-gu");
initParams.put("allow", "");//默认就是允许所有访问
initParams.put("deny", "192.168.5.60");
bean.setInitParameters(initParams);
return bean;
} //2、配置一个web监控的filter
@Bean
public FilterRegistrationBean webStatFilter() {
FilterRegistrationBean bean = new FilterRegistrationBean();
bean.setFilter(new WebStatFilter());
Map<String, String> initParams = new HashMap<>();
initParams.put("exclusions", "*.js,*.css,/druid/*");
bean.setInitParameters(initParams);
bean.setUrlPatterns(Arrays.asList("/*"));
return bean;
} }
druid去除广告:
参考:https://blog.csdn.net/weixin_42634808/article/details/86563048
Springboot中配置druid的更多相关文章
- springboot中配置druid允许一次执行多条sql
原文:https://blog.csdn.net/jiangjun0130/article/details/77868578 1:在配置文件中不需要指定wall防火墙filter. 配置如下: spr ...
- SpringBoot下配置Druid
什么是Druid:Druid是阿里发开的一套基于database的监控平台,相对于其他监控来说对于中文的支持更亲民.. 前言:最近这段时间发现项目整体运行响应速度较慢,打算对系统进行深层次的优化(尤其 ...
- 在SpringBoot中配置aop
前言 aop作为spring的一个强大的功能经常被使用,aop的应用场景有很多,但是实际的应用还是需要根据实际的业务来进行实现.这里就以打印日志作为例子,在SpringBoot中配置aop 已经加入我 ...
- springboot中配置主从redis
测试redis的主从配置 redis实例 文件夹名称如下 redis_master_s redis_slaver1_s redis_slaver2_s redis.conf文件 master的redi ...
- SpringBoot(八):SpringBoot中配置字符编码 Springboot中文乱码处理
SpringBoot中配置字符编码一共有两种方式 方式一: 使用传统的Spring提供的字符编码过滤器(和第二种比较,此方式复杂,由于时间原因这里先不介绍了,后续补上) 方式二(推荐使用) 在appl ...
- springboot中使用druid和监控配置
如果想要监控自己的项目的访问情况及查看配置信息,druid是一个很好的选择,可能你会问druid是什么?有什么用?优点是什么? Druid简介 Druid是阿里巴巴开源的数据库连接池,号称是Java语 ...
- springboot 中使用Druid 数据源提供数据库监控
一.springboot 中注册 Servlet/Filter/Listener 的方式有两种,1 通过代码注册 ServletRegistrationBean. FilterRegistration ...
- 在SpringBoot中配置定时任务
前言 之前在spring中使用过定时任务,使用注解的方式配置很方便,在SpringBoot中的配置基本相同,只是原来在spring中的xml文件的一些配置需要改变,在SpringBoot中也非常简单. ...
- springboot中配置过滤器以及可能出现的问题
在springboot添加过滤器有两种方式: 1.通过创建FilterRegistrationBean的方式(建议使用此种方式,统一管理,且通过注解的方式若不是本地调试,如果在filter中需要增加c ...
随机推荐
- WinForm使用DataGridView实现类似Excel表格的查找替换
在桌面程序开发过程中我们常常使用DataGridView作为数据展示的表格,在表格中我们可能要对数据进行查找或者替换. 其实要实现这个查找替换的功能并不难,记录下实现过程,不一定是最好的方式,但它有用 ...
- PAT乙级:1056 组合数的和 (15分)
PAT乙级:1056 组合数的和 (15分) 给定 N 个非 0 的个位数字,用其中任意 2 个数字都可以组合成 1 个 2 位的数字.要求所有可能组合出来的 2 位数字的和.例如给定 2.5.8,则 ...
- Python在ubuntu16.04上环境搭建
1.anaconda3安装 mkdir anaconda cd anaconda wget https://repo.continuum.io/archive/Anaconda3-4.4.0-Linu ...
- React优化
这里主要分析在函数式react中的优化,类组件有生命周期函数定义较明确 React的核心特征之一是单向数据流(props自上往下流) 这会导致一个问题:当父组件state更新后,其自身及其所有chil ...
- TheadLocal与synchronized
深入比较TheadLocal模式与synchronized关键字 ThreadLocal模式synchronized关键字都用于处理多线程并发访问变量的问题,只是二者处理问题的角度和思路不同. 1)T ...
- 流畅的python--函数
# # -*- coding: utf-8 -*-#from abc import ABC ,abstractclassmethodfrom collections import namedtuple ...
- 第八篇 -- 用U盘制作启动盘装Win10系统
下载装机吧:http://www.zhuangjiba.com 装Win10参考文章:http://www.zhuangjiba.com/bios/13249.html U盘启动盘制作 1.首先将U盘 ...
- Python3.6安装protobuf模块+将proto文件转换成pb2.py文件
Python对版本的对应即为苛刻,笔者第一次安装时遇到了很多坑,比如无法将proto文件转换成py文件,转换了之后文件无法使用,网上各种各样的解决办法都没有讲到重点.其实会出现各种各样的问题是由于版本 ...
- 基于单机redis的分布式锁实现
最近我们有个服务经常出现存储的数据出现重复,首先上一个系统流程图: 用户通过http请求可以通知任务中心结束掉自己发送的任务,这时候任务中心会通过MQ通知结束服务去结束任务保存数据,由于任务结束数据计 ...
- element UI表格行高、padding等设置报错问题
element UI里面表格的行高需要自己调整高度和设置padding,直接写style是不行的,里面有 : 1.row-style (行的 style) 2.header-row-styl (表 ...