当前位置:网站首页>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 
边栏推荐
- 使用递归或while循环获取父/子层级结构的名称
- QPM suspended window setting information
- js---获取对象数组中key值相同的数据,得到一个新的数组
- Throttling, anti chattering, new function, coriolism
- Thinkphp5 manual error reporting
- Flink入门——单词统计
- The shutter tabbar listener is called twice
- Flutter's brain map notes are easy to find and search!
- Redis notes (14) - persistence and data recovery (data persistence RDB and AOF, data recovery, mixed persistence)
- MapReduce&Yarn理论
猜你喜欢

How to create an IE tab in edge browser

Specific implementation comparison between different programming languages

2021 national vocational college skills competition (secondary vocational group) network security competition questions (1) detailed analysis tutorial

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

MapReduce & yarn theory

工企专利匹配数据(数十万数据量)1998-2014年

c语言语法基础之——局部变量及存储类别、全局变量及存储类别、宏定义 学习

Single sign on logic

The shutter tabbar listener is called twice

install opencv-contrib-dev to use aruco code
随机推荐
logback
欧冠比赛数据集(梅西不哭-离开巴萨也可能再创巅峰)
OpenCV depthframe -> pointcloud 导致 segmentation fault!
Record a time when the server was taken to mine
LeetCode 498. Diagonal traversal
自动化测试——关于unitest与pytest初始化共存问题
LeetCode 958. Completeness checking of binary tree
Code statistics tools cloc and SCC
The third-party extension package of thinkphp6.0 supports uploading to Alibaba cloud and qiniu cloud
SQL query duplicate record
A Style-Based Generator Architecture for Generative Adversarial Networks
节流,防抖,new函数,柯里化
软件测试---如何选择合适的正交表
Logview Pro can be used if the log is too large
A concise tutorial for getting started with go generics
c语言语法基础之——函数嵌套、递归 小程序斐波那契之和、阶乘
logback
QPM performance monitoring components - General
js---获取对象数组中key值相同的数据,得到一个新的数组
十万行事务锁,开了眼界了。