这篇文章主要介绍“如何在springboot中使用IDEA远程连接Debug”,在日常操作中,相信很多人在如何在springboot中使用IDEA远程连接Debug问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”如何在springboot中使用IDEA远程连接Debug”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!
创新互联是一家集网站建设,临安企业网站建设,临安品牌网站建设,网站定制,临安网站建设报价,网络营销,网络优化,临安网站推广为一体的创新建站企业,帮助传统企业提升企业形象加强企业竞争力。可充分满足这一群体相比中小企业更为丰富、高端、多元的互联网需求。同时我们时刻保持专业、时尚、前沿,时刻以成就客户成长自我,坚持不断学习、思考、沉淀、净化自己,让我们为更多的企业打造出实用型网站。
4.0.0 org.springframework.boot spring-boot-starter-parent 2.1.4.RELEASE com.remote.test remote_test 0.0.1-SNAPSHOT remote_test Demo project for Spring Boot 1.8 org.springframework.boot spring-boot-starter org.springframework.boot spring-boot-starter-test test org.springframework.boot spring-boot-starter-web org.junit.jupiter junit-jupiter-api RELEASE test org.apache.maven.plugins maven-shade-plugin 2.2 org.springframework.boot spring-boot-maven-plugin 2.1.4.RELEASE true false *:* META-INF/*.SF META-INF/*.DSA META-INF/*.RSA package shade ${project.artifactId}-${project.version}-all META-INF/spring.handlers META-INF/spring.factories META-INF/spring.schemas com.remote.test.remote_test.RemoteTestApplication
package com.remote.test.remote_test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import java.util.HashMap; import java.util.Map; @RestController @RequestMapping("remote/test") public class UserController { private static final Logger logger = LoggerFactory.getLogger(UserController.class); @PostMapping("selectByUserId") public String selectUserInfo(@RequestParam("userId") String userId) { try { MapuserInfo = new HashMap<>(); userInfo.put("userId",userId); userInfo.put("age",23); userInfo.put("name","yanshao"); userInfo.put("address","shanghai"); logger.info("Query user information by user ID. userInfo: {}",userInfo.toString()); return this.success(userInfo); } catch (Exception e) { logger.error("Query user information by user ID. userId:{} ", userId, e); return this.fail(); } } private String success(Object data){ Map res = new HashMap<>(); res.put("code",0); res.put("desc","success"); res.put("data",data); return res.toString(); } private String fail(){ Map res = new HashMap<>(); res.put("code",1); res.put("desc","fail"); return res.toString(); } }
输入:mvn clean package
,(大概需要等几分钟),最好在构建之前指定本地repository,就不需要重新下载jar包了。
指定socket port = 8081,指定准备debug的模块
a. 先在IDEA启动debug
b. 然后在终端输入命令:java -agentlib:jdwp=transport=dt_socket,server=n,address=localhost:8081 -jar remote_test-0.0.1-SNAPSHOT-all.jar
在准备请求的接口上标记断点
注意:必须先在IDEA启动Debug,然后再启动项目
➜ Desktop java -agentlib:jdwp=transport=dt_socket,server=n,address=localhost:8081 -jar remote_test-0.0.1-SNAPSHOT-all.jar
ERROR: transport error 202: connect failed: Connection refused
ERROR: JDWP Transport dt_socket failed to initialize, TRANSPORT_INIT(510)
JDWP exit error AGENT_ERROR_TRANSPORT_INIT(197): No transports initialized [debugInit.c:750]
到此,关于“如何在springboot中使用IDEA远程连接Debug”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注创新互联网站,小编会继续努力为大家带来更多实用的文章!