当前位置:网站首页>Druid data source for background monitoring
Druid data source for background monitoring
2022-06-26 09:51:00 【Ma cute's Ma cute】
1、 stay pom.xml Integrating Druid data sources in
<!-- Druid data source -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.2.1</version>
</dependency>
2、 stay application.yml Configure the connection database in
spring:
datasource:
username: root
password: 123456
# If the time zone is wrong , Just add a time zone configuration
url: jdbc:mysql://localhost:3306/product?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf-8
driver-class-name: com.mysql.cj.jdbc.Driver
# Specify the type of data source ,spring The default data source is hikari, Specify the Druid data source we introduced ourselves
type: com.alibaba.druid.pool.DruidDataSource
filters: stat,wall,log4j
# Log monitoring function , Configure monitoring statistics filters,stat: Monitoring statistics 、log4j: logging 、wall: defense sql Inject
server:
port: 8001
3、 To configure druid The most powerful function of data source - Background monitoring function
(1)、 Definition config Under folder DruidConfig.java file
@Configuration
public class DruidConfig {
@ConfigurationProperties(prefix = "spring.datasource") /* And application.yaml binding */
@Bean
public DataSource druidDataSource() {
return new DruidDataSource();
}
@Bean
/* Background monitoring function web.xml*/
// because springboot Built in servlet Containers , So there was no web.xml
public ServletRegistrationBean statViewServlet(){
ServletRegistrationBean<StatViewServlet> bean = new ServletRegistrationBean<>(new StatViewServlet(),"/druid/*"); // Get background monitoring
// Someone needs to log in and check in the background , Configure account 、 password
Map<String, String> map = new HashMap<>();
map.put("loginUsername","ml"); // Landed key Is constant
map.put("loginPassword","123456");
/* Who is allowed to access , If the parameter is empty , It means that anyone can access */
map.put("allow","");
/* No one is allowed to visit */
map.put("mm","192.168.12.3"); // prohibit ip Address access configuration
bean.setInitParameters(map); // Set initialization parameters
return bean;
}
@Bean
public FilterRegistrationBean webStatFilter(){
FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean();
filterRegistrationBean.setFilter(new WebStatFilter());
/* Which requests can be filtered out */
Map<String, String> map = new HashMap<>();
// These things don't count
map.put("exclusions","*.js,*.css,/druid/*");
return filterRegistrationBean;
}
}
4、 visit http://localhost:8001/druid
(1)、 The home page is as follows 
(2)、 The visit page is as follows 
(3)、 Use http://localhost:8001/add Implement the following code in the background
@GetMapping("/add")
public String add() {
String sql = "insert into student (sid,sname,sclass,tid) values('12344555',' Xiao Ming ','1602 class ','12356987')";
jdbcTemplate.update(sql);
return "add ok!";
}
And then click “sql monitor ” You can see the execution just now sql sentence , Realization sql Monitoring function 
Click to execute sql sentence , You can see the details 
边栏推荐
- jz2440---使用uboot烧录程序
- How to create an IE tab in edge browser
- install opencv-contrib-dev to use aruco code
- 2021-11-22 运动规划杂记
- Redis notes (16) - info instructions and command line tools (view memory, status, number of client connections, monitoring server, scan large keys, sampling server, execute batch commands, etc.)
- MySQL单表500万条数据增、删、改、查速度测试
- Notes on sports planning on November 22, 2021
- 深度学习(初识tensorflow2.版本)之三好学生成绩问题(1)
- [pulsar learning] pulsar Architecture Principle
- Jupyter Notebook遇到的问题
猜你喜欢

jz2440---使用uboot烧录程序

Detailed explanation of the network security competition questions (2) of the 2021 national vocational college skills competition (secondary vocational group)

What you need to know to test -- URL, weak network, interface, automation

Redis novice introduction

Install new version cmake & swig & tinyspline

WIN10系统实现Redis主从复制

【CVPR 2019】Semantic Image Synthesis with Spatially-Adaptive Normalization(SPADE)

Redis notes (14) - persistence and data recovery (data persistence RDB and AOF, data recovery, mixed persistence)

The first techo day Tencent technology open day, 628

install realsense2: The following packages have unmet dependencies: libgtk-3-dev
随机推荐
LeetCode 958. Completeness checking of binary tree
install realsense2: The following packages have unmet dependencies: libgtk-3-dev
A Style-Based Generator Architecture for Generative Adversarial Networks
online trajectory generation
Mysql database field query case sensitive setting
逻辑英语结构【重点】
halcon 光度立体
Logical English structure [key points]
爬虫相关文章收藏:pyppeteer 、Burpsuite
Does the go compiled executable have dynamic library links?
The first techo day Tencent technology open day, 628
LeetCode 498. 对角线遍历
LeetCode 958. 二叉树的完全性校验
Leetcode connected to rainwater series 42 (one dimension) 407 (2D)
Getting started with Flink - word statistics
Joint Noise-Tolerant Learning and Meta Camera Shift Adaptation for Unsupervised Person Re-ID
Jz2440 - - - utiliser le programme de gravure uboot
Badge series 8: generate a personalized Badge
online trajectory generation
libgstreamer-1.0. so. 0: cannot open shared object file: No such file or directory