springboot 整合druid

目录

    • 1. maven依赖
    • 2. yml配置
    • 3. druid配置类编写
    • 4. 后台性能监控

https://github.com/sevenyoungairye/spring-boot-study

  • druid优点:提供性能监控,配置灵活丰富

1. maven依赖

<!-- mysql驱动 springboot内置 --><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><scope>runtime</scope></dependency><!--druid 数据源--><dependency><groupId>com.alibaba</groupId><artifactId>druid</artifactId><version>1.1.21</version></dependency>

2. yml配置

spring:datasource:username: rootpassword: 123456# springboot默认数据源com.zaxxer.hikari.HikariDataSource # 比druid快url: jdbc:mysql://localhost:3306/mybatis_study?serverTimezone=GMTdriver-class-name: com.mysql.cj.jdbc.Driver# 切换成druid 有性能监控...type: com.alibaba.druid.pool.DruidDataSource# 下面为连接池的补充设置,应用到上面所有数据源中# 初始化大小,最小,最大initial-size: 5min-idle: 5max-active: 20# 配置获取连接等待超时的时间max-wait: 60000# 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒time-between-eviction-runs-millis: 60000# 配置一个连接在池中最小生存的时间,单位是毫秒min-evictable-idle-time-millis: 300000validation-query: SELECT 1 FROM DUALtest-while-idle: truetest-on-borrow: falsetest-on-return: false# 打开PSCache,并且指定每个连接上PSCache的大小pool-prepared-statements: true#   配置监控统计拦截的filters,去掉后监控界面sql无法统计,'wall'用于防火墙max-pool-prepared-statement-per-connection-size: 20filters: stat,walluse-global-data-source-stat: true# 通过connectProperties属性来打开mergeSql功能;慢SQL记录connect-properties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000

3. druid配置类编写

package cn.bitqian.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 java.util.HashMap;
import java.util.Map;/*** druid 配置类* @author echo lovely* @date 2020/10/23 22:01*/
@Configuration
public class DruidConfig {@ConfigurationProperties(prefix = "spring.datasource")@Beanpublic DruidDataSource druidDataSource() {return new DruidDataSource();}// 后台监控: web.xml ServletRegistrationBean// spring boot 内置了servlet 没有web.xml配置文件,所以用下面的方式配置@Beanpublic ServletRegistrationBean druidServlet() {ServletRegistrationBean servletRegistrationBean = newServletRegistrationBean(new StatViewServlet(), "/druid/*");Map<String, String> initParameters = new HashMap<>();// 后台登录的账号密码// initParameters.put("jmxUsername", "admin"); // loginUsername// initParameters.put("jmxPassword", "123"); // loginPasswordinitParameters.put("loginUsername", "admin"); // loginUsernameinitParameters.put("loginPassword", "123"); // loginPassword// 允许访问 白名单initParameters.put("allow", "127.0.0.1");// initParameters.put("deny", "168.403.432.234"); 禁止访问黑名单servletRegistrationBean.setInitParameters(initParameters);return servletRegistrationBean;}/*** 过滤器* @return null*/@Beanpublic FilterRegistrationBean filterRegistrationBean() {FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean();// 过滤请求filterRegistrationBean.setFilter(new WebStatFilter());Map<String, String> initParameters = new HashMap<>();// 设置静态资源放行initParameters.put("exclusions", "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*");filterRegistrationBean.setInitParameters(initParameters);return filterRegistrationBean;}}

4. 后台性能监控



请忽略广告…

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/420566.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Ubuntu 查看默认软件安装位置

tags: Linux 方法 1&#xff1a;在命令行输入&#xff1a;dpkg -L 软件包名&#xff1b;方法 2&#xff1a;在/var/cache/apt/archives找的你安装程序的包&#xff0c;然后用gdebi-gtk软件包名可以查看具体安装在什么位置。转载于:https://www.cnblogs.com/svitter/p/4011433.h…

maven 项目管理和构建工具

mvn1. maven 是什么2. maven能解决什么问题3. maven 需要配置和下载4. 使用eclipse创建maven项目5. xml依赖配置 作用范围6. maven的常用命令1. maven 是什么 Maven 在美国是一个口语化的词语&#xff0c;代表专家、内行的意思&#xff0c; Maven是一个项目管理工具&#xff0…

大数据----基于sogou.500w.utf8数据的MapReduce编程

目录 一、前言二、准备数据三、编程实现3.1、统计出搜索过包含有“仙剑奇侠传”内容的UID及搜索关键字记录3.2、统计rank<3并且order>2的所有UID及数量3.3、上午7-9点之间&#xff0c;搜索过“赶集网”的用户UID3.4、通过Rank&#xff1a;点击排名 对数据进行排序 四、参…

Java源代码分析与生成

源代码分析&#xff1a;可使用ANTLRANTLR是开源的语法分析器&#xff0c;可以用来构造自己的语言&#xff0c;或者对现有的语言进行语法分析。JavaParser 对Java代码进行分析CodeModel 用于生成Java代码(但对于已有代码的支持可能有问题) 转载于:https://www.cnblogs.com/laoni…

springboot 整合mybatis实现curd

springboot 整合mybatispom文件mvc 架构application.properties 扩展配置&#xff0c;druid配置类项目地址&#xff1a;https://github.com/sevenyoungairye/spring-boot-study/tree/main/springboot-mybatis-05pom文件 <!--整合mybatis--><dependency><groupId…

关于android 调用网页隐藏地址栏

首先创建项目&#xff0c;在main.xml里 添加好WebView控件R.id为webview1。 HelloWebView.java 代码 package liu.ming.com; import android.app.Activity;import android.os.Bundle;import android.view.KeyEvent;import android.webkit.WebView;import android.webkit.WebVie…

spring security 认证与权限控制

目录1. 使用授权和认证的必要性2. spring security 与 shiro 与 过滤器&#xff0c;拦截器3. 具体配置使用项目地址&#xff1a;https://github.com/sevenyoungairye/spring-boot-study/tree/main/springboot-security-061. 使用授权和认证的必要性 什么是安全框架&#xff0c…

CodeIgniter框架下载辅助函数的一个小bug

if (strpos($_SERVER[HTTP_USER_AGENT], "MSIE") ! FALSE){header(Content-Type: .$mime); // <---1)这里header(Content-Disposition: attachment; filename".$filename.");header(Expires: 0);header(Cache-Control: must-revalidate, post-check0, p…

win7 cmd命令行窗口 宽度无法变大 自由调整大小

偶然遇到了这个问题,百度查到了解决方案,执行一个bat批处理命令. mode con lines40 mode con cols160 color 250 cls cmd转载于:https://www.cnblogs.com/DreamDrive/p/4017970.html

springboot 与shiro整合

shiro~ shiro快速入门springboot 整合shiro核心目标清爽pom用户认证授权认证&#xff0c;与数据库交互shiro configuration核心controller 获取shiro 中的token页面控制功能的隐藏和显示https://github.com/sevenyoungairye/spring-boot-study/tree/main/springboot-shiro-07sh…

jvm内存设置

摘抄自&#xff1a;http://www.cnblogs.com/fyj218/archive/2011/07/19/2110570.html 在eclipse根目录下打开eclipse.ini&#xff0c;默认内容为&#xff08;这里设置的是运行当前开发工具的JVM内存分配&#xff09;&#xff1a;-vmargs-Xms40m-Xmx256m-vmargs表示以下为虚拟机…

swagger接口文档使用

swagger接口文档一&#xff0c;swagger简介前后端分离swagger 诞生二&#xff0c;springboot集成swagger依赖编写helloworld接口配置swagger > config 配置类测试运行三&#xff0c;配置swaggerswagger 配置扫描接口如何做到只在生产环境中启动swagger&#xff1f;配置api文…

异步任务,邮箱任务,定时任务

task~异步任务邮箱任务定时任务源码下载异步任务 开启多线程&#xff0c;我飞了。 package cn.bitqian.service;import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service;/*** 异步任务 目的 多线程&#xff0c;交给spring托…

iframe在ipad safari的显示

今 天要在web中嵌套一个网址或本地HTML&#xff0c;用到了iframe&#xff0c;在电脑上设置scrolling‘auto’&#xff0c;宽度高度&#xff0c;会有滚动条出现。而在 ipad上会全部显示整个网页的宽度高度。scrolling属性无效。原来在html5中的iframe已经只有剩下src的属性。 但…

IOS 开发中 Whose view is not in the window hierarchy 错误的解决办法

在 IOS 开发当中经常碰到 whose view is not in the window hierarchy 的错误&#xff0c;该错误简单的说&#xff0c;是由于 "ViewController" 还没有被加载&#xff0c;就调用该 ViewController 或者 ViewController 内的方法时&#xff0c;就会报这个错误。在不同…

maven传递依赖

目录1. 依赖传递2. 什么是依赖冲突3. 怎么解决4. 项目聚合maven是一个项目管理的工具&#xff0c;从项目的构建到项目开发&#xff0c;再到项目的测试&#xff0c;项目上线&#xff0c;都可一键管理。1. 那么&#xff0c;还有maven是如何管理项目中所用到的jar版本冲突&#xf…

使用apache FileUtils下载文件

目录工具代码实现测试工具 <dependency><groupId>commons-io</groupId><artifactId>commons-io</artifactId><version>2.5</version></dependency>或者 https://mvnrepository.com/artifact/commons-io/commons-io/2.7 然后放…

二分图多重匹配

在二分图的最大匹配中&#xff0c;每个点&#xff08;不管是X集合还是Y集合&#xff09;最多只能与一条匹配边相关联&#xff0c; 然而&#xff0c;经常有这种问题&#xff0c;即二分图的一个点可以和多条匹配边相关联&#xff0c;但有上限&#xff0c;即cap[i]表示点i最多能和…

springmvc,spring,hibernate5.0整合

目录1. pom依赖2. web.xml3. spring核心配置文件3.1 jdbc配置信息3.2 sping 配置文件4. 实体映射5. 项目结构5.1 curd5.2 页面6. 测试1. spring版本 5.1.5 RELEASE 2. hibernate版本 5.3.9.Final 3. 数据源使用c3p0项目使用eclipse2017 maven构建, 完成学生的新增&#xff0c;…