当前位置:网站首页>Shocked, you can't debug remotely

Shocked, you can't debug remotely

2022-06-09 02:48:00 Hua Weiyun

Accidentally learn to see a blog , Just know that there is a remote debug A technique for debugging , Actually , Find the server before bug When , I have always hoped for such a technology , Instead of relying on checking logs every time , Of course, most of the time , It is enough to rely on logs , Reasonable input log , Compared with debug It can locate problems faster and better .

The main steps , Reference is not particularly complicated

1. introduce web rely on It is best to 2.2.6.RELEASE The above

<dependency>   <groupId>org.springframework.boot</groupId>   <artifactId>spring-boot-starter-web</artifactId></dependency>

2. Package to listen jar package

Add plug-ins ,maven Just pack it

<plugin>    <groupId>org.springframework.boot</groupId>    <artifactId>spring-boot-maven-plugin</artifactId>    <configuration>        <jvmArguments>-Xdebug -Xrunjdwp:transport=dt_socket,address=5005,server=y,suspend=n</jvmArguments>    </configuration></plugin>

Their meanings are as follows

-Xdebug notice JVM With debug Way to run

-Xrunjdwp notice JVM Use the run debug environment , It is followed by a series of attribute parameters

        transport: Data transmission mode dt_socket socket Mode transfer ,dt_shmem Refers to shared memory

        address: The port number of the debugging server , Client connection use

        server: Whether to act as a debugging server

        suspend: Whether to debug the client

3. Start agent listening jar package

java -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005 -jar xxx.jar Start the just packed jar package

If appear   It indicates that the startup is successful

4. Use IDEA,Remote Mode start

Select... In startup mode remote, And enter the corresponding port number

[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-3rzwtdYm-1623688298229)(image-20210613230023399.png)]

[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-l0edF9KU-1623688298231)(image-20210613230200362.png)]

Then start the service .

5. Breakpoint debugging

Note that the open project must be consistent with the server

In the code , Make corresponding breakpoints , Then access the server interface . This will be the same as local debugging

Adjust the corresponding parameters , The service will be adjusted accordingly

原网站

版权声明
本文为[Hua Weiyun]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/159/202206081114286735.html