当前位置:网站首页>You still can't remotely debug idea? Come and have a look at my article. It's easy to use
You still can't remotely debug idea? Come and have a look at my article. It's easy to use
2022-06-13 05:52:00 【cx7】
1、 long-range DEBUG The necessity of
Due to the difference of deployment environment , I believe many friends have encountered that the functions normally tested in the development environment appear in the test environment or even the production environment bug The situation of . In general , The means that can be taken by the production environment are relatively single , That is, get the running environment context by logging , Analyze the log file and try to reproduce bug. This will bring many problems , First , Log analysis is a time-consuming work ; secondly , Existing logging does not necessarily reflect the problem , You may need to repeat this process many times ( Analysis log -> Guess the problem -> Add log -> Deploy -> Get log ) To slowly approach the problem . If it's a test environment , We also have an alternative —— Remote debugging —— Put the program in the test environment as debug mode , Use on this machine IDEA Set breakpoints in the project for debugging .
2、IDEA structure SpringBoot Test project
Here I used the previous test demo, Dependency basically does not introduce anything , Below redis Dependency was introduced by myself , You don't need to introduce .
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.cxk</groupId>
<artifactId>redis</artifactId>
<version>1.0-SNAPSHOT</version>
<parent>
<artifactId>spring-boot-starter-parent</artifactId>
<groupId>org.springframework.boot</groupId>
<version>2.3.5.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency>
</dependencies>
</project>
yaml perhaps properties Just add a port number to the file
server.port=8999
And then just make an interface :
package com.cxk.controller.main;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class MyController {
@RequestMapping("/test2")
public String execute2() {
String s1 = 1+"";
String s2 = 2+"";
String s3 = s2+s1;
return " --- " + s3;
}
}
Then let's start postman Test it
3、 test Demo The project configuration supports remote debugging
pom.xml Internal configuration jvmArguments Parameters -Xdebug -Xrunjdwp:transport=dt_socket,address=5005,server=y,suspend=n
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.3.7.RELEASE</version>
<configuration>
<jvmArguments>-Xdebug -Xrunjdwp:transport=dt_socket,address=5005,server=y,suspend=n </jvmArguments>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>8</source>
<target>8</target>
<encoding>utf-8</encoding>
</configuration>
</plugin>
</plugins>
</build>
With this configuration , The packaged project publisher , Can support remote DEBUG;
Detailed description of specific parameters :
-Xdebug
notice JVM Working in DEBUG In mode ;-Xrunjdwp
notice JVM Use (Java debug wire protocol) Operation and debugging environment . This parameter also contains a series of debugging options ;transport
The transmission mode of debugging data is specified ,dt_socket
Refers to using SOCKET Pattern , have other dt_shmem
Using shared memory , among ,dt_shmem
Only applicable to Windows platform ;address
The port number of the debugging server , The port number used by the client to connect to the server ;server=y/n
VM Does it need to be executed as a debugging server ;suspend=y/n
Whether to start after debugging the client to establish a connection VM;
4、IDEA pack jar
In this step, everyone may , Here I'm going to say a few words
If you don't know how to pack, look carefully , Point at the top right Maven,
Then execute in the following order , I didn't do it here test Options , If necessary, you can execute this option .
After the execution , Will be in target Create one in the directory jar package
Then copy this to the desktop to run , Here execute the following command .java -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005 -jar redis-1.0-SNAPSHOT.jar
The second line will indicate that you are listening 5005 port .
Then the next step is to make a breakpoint where the breakpoint is needed ,
Then we configure the remote DEBUG To configure .
Click on Edit Configuration A page will pop up , Then we click on the... In the upper left corner + Number , find Remote Options 、 Configure as follows . there 5005 It is the listening port number mentioned above . Then later apply. Then click on the bug in the upper right corner .
Click on the run DEBUG after , The pop-up window indicates that the connection has been made .
Then let's go Postman Test it .
Pay attention : The path address of the request here is you jar The address of the package deployment and the port number configured in the project . Then the breakpoint enters . Be accomplished .
边栏推荐
- 使用cmake交叉編譯helloworld
- About Evaluation Metrics
- Hump naming and underlining
- How to Algorithm Evaluation Methods
- Exception after repeated application redeployment on tongweb: application instance has been stopped already or outofmemoryerror:metaspace
- Leetcode- reverse string - simple
- Information collection for network security (2)
- Tongweb crawl performance log script
- Web site learning and sorting
- ArrayList loop removes the pit encountered
猜你喜欢
ffmpeg 下载后缀为.m3u8的视频文件
Comment procéder à l'évaluation des algorithmes
Shardingsphere JDBC exception: no table route info
17 servicetask of flowable task
Three paradigms of MySQL
中断处理过程
Interrupt processing
SPI primary key generation strategy for shardingsphere JDBC
Config server configuration center of Nacos series
Building a stand-alone version of Nacos series
随机推荐
Initial redis experience
JS output uincode code
No assessment summary
Leetcode- string addition - simple
Set the correct width and height of the custom dialog
Tongweb customs clearance guidelines
Cross compile HelloWorld with cmake
Misunderstanding of tongweb due to ease of use
The reason why the process cannot be shut down after a spark job is executed and the solution
Leetcode- find all missing numbers in the array - simple
Leetcode Hamming distance simple
SPI primary key generation strategy for shardingsphere JDBC
17 servicetask of flowable task
ffmpeg 下载后缀为.m3u8的视频文件
Leetcode- longest palindrome string - simple
Web site learning and sorting
MySQL installation in Linux Environment
Leetcode- find a difference - simple
= = relation between int and integer
AUTOSAR实战教程pdf版