Performance analysis plug-in in MyBatisPlus

Performance analysis plug-in in MyBatisPlus

In our usual development, we will encounter some slow SQL. test! druid...

MyBatisPlus also provides performance analysis plug-ins, if it exceeds this time, it will stop running!

1. Import the plugin

2. Test and use

See it later

@Profile annotation

Before understanding the performance analysis plug-in in MyBatisPlus, you first need to know the @Profile annotation.

The role of this annotation: specify the environment in which the component can be registered in the container, if not specified, the component can be registered in any environment

Development environment develop, test environment test, production environment master

@Profile({
    
    "dev","test","master"})//表示在dev开发和test测试和master生产环境中指定的组件都可以被注册到容器中
@Profile({
    
    "dev","test"})//表示在dev开发和test测试环境中指定的组件才能被注册到容器中
@Profile("dev")//表示只有在dev开发环境中指定的组件才能被注册到容器中
次注解通常会和@Bean注解搭配使用

The example in the figure below means that components can only be registered in the container under the dev development or test environment, as shown in the figure below:

Insert picture description here

The configuration file in SpringBoot needs to set the environment. The environment must be a dev development environment or a test test environment. Otherwise, the plug-in cannot be successfully registered in the container. The environment settings are as follows:

Insert picture description here

Configure the performance analysis plug-in PerformanceInterceptor in the configuration class of MyBatisPlus

The configuration is as follows:

Insert picture description here

Specify the dev development environment in the SpringBoot configuration file

As shown below:

Insert picture description here

Test performance analysis plugin

The query code is as follows:

Insert picture description here

The log information corresponding to the query code is as follows:

Insert picture description here

After setting the maximum time allowed for sql statement execution above to be 100ms, the corresponding error in the log above disappears, the process is as follows:

Insert picture description here

Insert picture description here

Guess you like

Origin blog.csdn.net/qq_45950109/article/details/112688873