资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

如何在springboot中使用IDEA远程连接Debug-创新互联

这篇文章主要介绍“如何在springboot中使用IDEA远程连接Debug”,在日常操作中,相信很多人在如何在springboot中使用IDEA远程连接Debug问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”如何在springboot中使用IDEA远程连接Debug”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!

创新互联长期为上千余家客户提供的网站建设服务,团队从业经验10年,关注不同地域、不同群体,并针对不同对象提供差异化的产品和服务;打造开放共赢平台,与合作伙伴共同营造健康的互联网生态环境。为马鞍山企业提供专业的成都做网站、网站制作,马鞍山网站改版等技术服务。拥有十余年丰富建站经验和众多成功案例,为您定制开发。

 1、先创建一个准备远程调试的Demo,注意构建项目的配置



	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 {
            Map userInfo = 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();
    }
 
}

2、打包

输入:mvn clean package,(大概需要等几分钟),好在构建之前指定本地repository,就不需要重新下载jar包了。

如何在springboot中使用IDEA远程连接Debug

如何在springboot中使用IDEA远程连接Debug

3、在IDEA配置远程Debug

指定socket port = 8081,指定准备debug的模块

如何在springboot中使用IDEA远程连接Debug

4、在终端启动刚才打好的jar包

a. 先在IDEA启动debug

如何在springboot中使用IDEA远程连接Debug

b. 然后在终端输入命令:java -agentlib:jdwp=transport=dt_socket,server=n,address=localhost:8081 -jar remote_test-0.0.1-SNAPSHOT-all.jar

如何在springboot中使用IDEA远程连接Debug

5、测试

在准备请求的接口上标记断点

如何在springboot中使用IDEA远程连接Debug

如何在springboot中使用IDEA远程连接Debug

如何在springboot中使用IDEA远程连接Debug

注意:必须先在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”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注创新互联网站,小编会继续努力为大家带来更多实用的文章!


标题名称:如何在springboot中使用IDEA远程连接Debug-创新互联
本文地址:http://cdkjz.cn/article/cecpeh.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220