-
9 — springboot整合jdbc、druid、druid实现日志监控 — 更新完毕
1、整合jdbc、druid
1)、导入依赖
|
|
|
<dependency> |
|
<groupId>org.springframework.boot</groupId> |
|
<artifactId>spring-boot-starter-jdbc</artifactId> |
|
</dependency> |
|
|
|
<dependency> |
|
<groupId>mysql</groupId> |
|
<artifactId>mysql-connector-java</artifactId> |
|
<scope>runtime</scope> |
|
</dependency> |
|
|
|
|
|
<dependency> |
|
<groupId>org.springframework.boot</groupId> |
|
<artifactId>spring-boot-starter-test</artifactId> |
|
<scope>test</scope> |
|
</dependency> |
|
2)、编写application.yml
|
|
|
spring: |
|
datasource: |
|
driver-class-name: com.mysql.jdbc.Driver |
|
url: jdbc:mysql://localhost:3306/mybatis_spring?useUnicode=true&characterEncoding=utf-8 |
|
username: root |
|
password: "072413" |
|
3)、测试
2、整合druid
1)、导入依赖
|
|
|
<!-- 要玩druid的话,需要导入下面这个依赖 --> |
|
<dependency> |
|
<groupId>com.alibaba</groupId> |
|
<artifactId>druid-spring-boot-starter</artifactId> |
|
<version>1.1.10</version> |
|
</dependency> |
|
2)、然后yml文件做一下修改
3)、测试
3、用druid实现日志监控
1)、注意点 ———— 需要web启动器支持
|
|
|
<!-- 玩druid实现监控日志,需要web启动器支持,因为:druid的statViewServlet本质是继承了servlet, |
|
因此:需要web的依赖支持 / servlet支持 |
|
--> |
|
<dependency> |
|
<groupId>org.springframework.boot</groupId> |
|
<artifactId>spring-boot-starter-web</artifactId> |
|
</dependency> |
|
2)、编写配置
|
|
|
package cn.xiegongzi.config; |
|
|
|
// 这个类是为了延伸druid的强大功能 ————— 监控后台 |
|
// 注意:这个需要spring的web启动器支持,即:这个监控后台的本质StatViewServlet就是servlet,所以需要servlet支持 |
|
|
|
import com.alibaba.druid.support.http.StatViewServlet; |
|
import org.springframework.boot.web.servlet.ServletRegistrationBean; |
|
import org.springframework.context.annotation.Bean; |
|
import org.springframework.context.annotation.Configuration; |
|
|
|
import java.util.HashMap; |
|
|
|
|
|
public class DruidConfig { |
|
|
|
|
|
public ServletRegistrationBean StatViewServlet() { |
|
|
|
ServletRegistrationBean bean = new ServletRegistrationBean<>(new StatViewServlet(), "/druid/*"); |
|
|
|
HashMap<String, String> initParameters = new HashMap<>(); |
|
|
|
// 下面这些参数可以在 com.alibaba.druid.support.http.StatViewServlet |
|
// 的父类 com.alibaba.druid.support.http.ResourceServlet 中找到 |
|
initParameters.put("loginUsername", "zixieqing"); // 登录日志监控的用户名 |
|
initParameters.put("loginPassword", "072413"); // 登录密码 |
|
|
|
initParameters.put("allow", "`localhost`"); // 运行谁可以访问日志监控 |
|
|
|
bean.setInitParameters(initParameters); |
|
return bean; |
|
} |
|
} |
|
3)、效果如下
作者:紫邪情
出 处:https://www.cnblogs.com/xiegongzi/p/15542655.html
最新更新
求1000阶乘的结果末尾有多少个0
详解MyBatis延迟加载是如何实现的
IDEA 控制台中文乱码4种解决方案
SpringBoot中版本兼容性处理的实现示例
Spring的IOC解决程序耦合的实现
详解Spring多数据源如何切换
Java报错:UnsupportedOperationException in Col
使用Spring Batch实现批处理任务的详细教程
java中怎么将多个音频文件拼接合成一个
SpringBoot整合ES多个精确值查询 terms功能实
数据库审计与智能监控:从日志分析到异
SQL Server 中的数据类型隐式转换问题
SQL Server中T-SQL 数据类型转换详解
sqlserver 数据类型转换小实验
SQL Server数据类型转换方法
SQL Server 2017无法连接到服务器的问题解决
SQLServer地址搜索性能优化
Sql Server查询性能优化之不可小觑的书签查
SQL Server数据库的高性能优化经验总结
SQL SERVER性能优化综述(很好的总结,不要错
uniapp/H5 获取手机桌面壁纸 (静态壁纸)
[前端] DNS解析与优化
为什么在js中需要添加addEventListener()?
JS模块化系统
js通过Object.defineProperty() 定义和控制对象
这是目前我见过最好的跨域解决方案!
减少回流与重绘
减少回流与重绘
如何使用KrpanoToolJS在浏览器切图
performance.now() 与 Date.now() 对比