当前位置:网站首页>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 
边栏推荐
- Solve Django's if Version (1, 3, 3): raise improverlyconfigured ('mysqlclient 1.3.3 or new is required
- PHP extracts TXT text to store the domain name in JSON data
- LeetCode 剑指 Offer II 091.粉刷房子 - 原地修改
- Meaning of go runtime
- Specific implementation comparison between different programming languages
- Use recursion or a while loop to get the name of the parent / child hierarchy
- Champions League data set (Messi doesn't cry - leaving Barcelona may reach another peak)
- Click the mask layer to close the pop-up window
- 异常记录-23
- 做测试需要知道的内容——url、弱网、接口、自动化、
猜你喜欢

Mysql database field query case sensitive setting

Redis notes (15) - Pipeline (the client packages and sends batch commands to save network overhead)

逻辑英语结构【重点】

The shutter tabbar listener is called twice

MapReduce & yarn theory

Thinkphp5 manual error reporting

Redis 新手入门

install opencv-contrib-dev to use aruco code

Curriculum learning (CL)

install realsense2: The following packages have unmet dependencies: libgtk-3-dev
随机推荐
LeetCode 0710.黑名单中的随机数 - 预处理实现O(1)取值
深度学习(初识tensorflow2.版本)之三好学生成绩问题(1)
Redis notes (12) - single thread architecture (non blocking IO, multiplexing) and multiple asynchronous threads
异常记录-23
c语言语法基础之——函数定义学习
Redis notes (15) - Pipeline (the client packages and sends batch commands to save network overhead)
A Style-Based Generator Architecture for Generative Adversarial Networks
SQL高级教程
点击遮罩层关闭弹窗
Upgrade idea to 2021.2 shortcut keys
PHP extracts TXT text to store the domain name in JSON data
Redis notes (14) - persistence and data recovery (data persistence RDB and AOF, data recovery, mixed persistence)
软件测试---如何选择合适的正交表
SQL advanced tutorial
QPM performance monitoring components - General
MapReduce & yarn theory
The first problem troubleshooting process of re disk
logback
2021年全国职业院校技能大赛(中职组)网络安全竞赛试题(1)详细解析教程
Introduction to QPM