Springboot整合druid

application.yml

# 此处用来配置数据库
spring:
datasource:
url: jdbc:mysql://192.168.0.169:3306/jpa
username: root
password: xiaoyan
type: com.alibaba.druid.pool.DruidDataSource
driver-class-name: com.mysql.cj.jdbc.Driver
# 下面为连接池的补充设置,应用到上面所有数据源中, 可以写, 可以不写
# 初始化大小,最小,最大
initialSize: 5
minIdle: 5
maxActive: 20
# 配置获取连接等待超时的时间
maxWait: 60000
# 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
timeBetweenEvictionRunsMillis: 60000
# 配置一个连接在池中最小生存的时间,单位是毫秒
minEvictableIdleTimeMillis: 300000
validationQuery: SELECT 1 FROM DUAL

DruidConfig

@Configuration
public class DruidConfig { @ConfigurationProperties(prefix = "spring.datasource")
@Bean
public DataSource druid() {
return new DruidDataSource();
} @Bean
public ServletRegistrationBean<StatViewServlet> statViewServlet() {
ServletRegistrationBean<StatViewServlet> registrationBean = new ServletRegistrationBean<>();
registrationBean.setServlet(new StatViewServlet());
registrationBean.setUrlMappings(Collections.singletonList("/druid/*"));
//设置初始化参数
Map<String, String> initMap = new HashMap<>();
// 登录账户密码
initMap.put("loginUsername", "admin");
initMap.put("loginPassword", "123456");
initMap.put("allow", "");
initMap.put("deny", "");
registrationBean.setInitParameters(initMap);
return registrationBean;
} @Bean
public FilterRegistrationBean<WebStatFilter> webStatFilter() {
FilterRegistrationBean<WebStatFilter> registrationBean = new FilterRegistrationBean<>();
registrationBean.setFilter(new WebStatFilter());
registrationBean.setUrlPatterns(Collections.singletonList("/*"));
//设置初始化参数
Map<String, String> initMap = new HashMap<>(1);
initMap.put("exclusions", "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*");
registrationBean.setInitParameters(initMap);
return registrationBean;
}
}

数据监控地址:http://localhost:8080/druid

Springboot整合druid的更多相关文章

  1. SpringBoot整合Druid数据连接池

    SpringBoot整合Druid数据连接池 Druid是什么? Druid是Alibaba开源的的数据库连接池.Druid能够提供强大的监控和扩展功能. 在哪里下载druid maven中央仓库: ...

  2. 【SpringBoot | Druid】SpringBoot整合Druid

    SpringBoot整合Druid Druid是个十分强大的后端管理工具,具体的功能和用途请问阿里爸爸 1. 在pom.xml中导入包 <!-- alibaba 的druid数据库连接池 --& ...

  3. springboot整合druid、mybatis

    目的: 1.springboot配置数据库连接池druid 测试druid中url监控 2.springboot整合mybatis 测试查删案例 3.springboot整合pagehelper sp ...

  4. springboot整合druid和配置资源监控

    1.添加依赖,在maven repository中搜索 <dependency> <groupId>com.alibaba</groupId> <artifa ...

  5. springboot整合druid连接池、mybatis实现多数据源动态切换

    demo环境: JDK 1.8 ,Spring boot 1.5.14 一 整合durid 1.添加druid连接池maven依赖 <dependency> <groupId> ...

  6. 【SpringBoot笔记】SpringBoot整合Druid数据连接池

    废话少说,按SpringBoot的老套路来. [step1]:添加依赖 <!-- 数据库连接池 --> <dependency> <groupId>com.alib ...

  7. SpringBoot整合Druid数据源

    关于SpringBoot数据源请参考我上一篇文章:https://www.cnblogs.com/yueshutong/p/9409295.html 一:Druid介绍 1. Druid是什么? Dr ...

  8. SpringBoot整合Druid(阿里巴巴)数据源

    (1).添加相关依赖 <dependency> <groupId>org.springframework.boot</groupId> <artifactId ...

  9. springboot整合druid数据库连接池并开启监控

    简介 Druid是一个关系型数据库连接池,它是阿里巴巴的一个开源项目.Druid支持所有JDBC兼容的数据库,包括Oracle.MySQL.Derby.PostgreSQL.SQL Server.H2 ...

随机推荐

  1. ideal的maven工程启动时老是报错,提示web.xml里面的监听器找不到,但是实际又是存在的

    -X clean compile package -Dmaven.repo.local=D:\repository-pss -Dmaven.test.skip=true maven仓库地址

  2. Vue 中 diff 算法后更新 DOM 的方法

    vue 2.0加入了 virtual dom,在 node_modules\vue\src\core\vdom\patch.js 中会对虚拟 DOM 进行 diff 算法等,然后更新 DOM. 网上的 ...

  3. 引擎设计跟踪(九.14.3) deferred shading 准备

    目前做的一些准备工作 1.depth prepass for forward shading. 做depth prepass的原因是为了完善渲染流程, 虽然架构上支持多个pass, 但实际上从来没有测 ...

  4. WMware Vsphere取消某虚机的漂移

    由于一些业务特性,有一些虚机不应该完全受集群DSR控制.下面记录一下如何更改某一虚机的漂移属性. 1.环境 VMware Vsphere web client 6.5 2.点击需要配置虚机所在的集群, ...

  5. C#如何调用以管理员身份运行的cmd命令提示符

    windows自从vista.win7.win8/8.1以及win10以来,命令行提示符分为两种模式,一种是普通用户模式,一种的管理员模式,很多情况下,我们的程序需要在命令提示符(管理员身份)的状况下 ...

  6. mysql入门学习笔记

    MySQL的登陆和退出 mysql -u 用户名 -p 密码 #登陆 quit #退出(exit or \q) 具体参数: 参数 描述 -D,--database=name 打开指定数据库 -deli ...

  7. ubuntu安装yaf

    ubuntu 下PHP安装yaf扩展,需要先安装其他软件 sudo apt-get install libncurses5-dev libpcre3-dev pcre-devel -y 然后再执行 p ...

  8. upstream timed out (10060: A connection attempt failed because the connected party did not properly respond

    openresty 错误日志报错内容: // :: [error] #: * upstream timed : A connection attempt failed because the conn ...

  9. idea 的方法上面注释在格式化后换行问题

    通过/**生成的方法上面的模板样式是: /** * 楼盘 * @param build * @return */ 格式化代码后是: /** * 楼盘 * * @param build * @retur ...

  10. python基础知识8---条件和循环

    阅读目录 一.if语句 1.1 功能 1.2 语法 1.2.1:单分支,单重条件判断 1.2.2:单分支,多重条件判断 1.2.3:if+else 1.2.4:多分支if+elif+else 1.2. ...