这篇文章主要介绍“如何在springboot中使用IDEA远程连接Debug”,在日常操作中,相信很多人在如何在springboot中使用IDEA远程连接Debug问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”如何在springboot中使用IDEA远程连接Debug”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!
创新互联长期为上千余家客户提供的网站建设服务,团队从业经验10年,关注不同地域、不同群体,并针对不同对象提供差异化的产品和服务;打造开放共赢平台,与合作伙伴共同营造健康的互联网生态环境。为马鞍山企业提供专业的成都做网站、网站制作,马鞍山网站改版等技术服务。拥有十余年丰富建站经验和众多成功案例,为您定制开发。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”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注创新互联网站,小编会继续努力为大家带来更多实用的文章!