<?xml version="1.0" encoding="UTF-8"?> <project xsi:schemalocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelversion>4.0.0</modelversion> <parent> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-starter-parent</artifactid> <version>2.1.4.RELEASE</version> <relativepath></relativepath> <!-- lookup parent from repository --> </parent> <groupid>com.remote.test</groupid> <artifactid>remote_test</artifactid> <version>0.0.1-SNAPSHOT</version> <name>remote_test</name> <description>Demo project for Spring Boot</description> <properties> <java.version>1.8</java.version> </properties> <dependencies> <dependency> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-starter</artifactid> </dependency> <dependency> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-starter-test</artifactid> <scope>test</scope> </dependency> <dependency> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-starter-web</artifactid> </dependency> <dependency> <groupid>org.junit.jupiter</groupid> <artifactid>junit-jupiter-api</artifactid> <version>RELEASE</version> <scope>test</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupid>org.apache.maven.plugins</groupid> <artifactid>maven-shade-plugin</artifactid> <version>2.2</version> <dependencies> <dependency> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-maven-plugin</artifactid> <version>2.1.4.RELEASE</version> </dependency> </dependencies> <configuration> <keepdependencieswithprovidedscope>true</keepdependencieswithprovidedscope> <createdependencyreducedpom>false</createdependencyreducedpom> <filters> <filter> <artifact>*:*</artifact> <excludes> <exclude>META-INF/*.SF</exclude> <exclude>META-INF/*.DSA</exclude> <exclude>META-INF/*.RSA</exclude> </excludes> </filter> </filters> </configuration> <executions> <execution> <phase>package</phase> <goals> <goal>shade</goal> </goals> <configuration> <finalname>${project.artifactId}-${project.version}-all</finalname> <transformers> <transformer> <resource>META-INF/spring.handlers</resource> </transformer> <transformer> <resource>META-INF/spring.factories</resource> </transformer> <transformer> <resource>META-INF/spring.schemas</resource> </transformer> <transformer></transformer> <transformer> <!--根据项目的全名指定启动类--> <mainclass>com.remote.test.remote_test.RemoteTestApplication</mainclass> </transformer> </transformers> </configuration> </execution> </executions> </plugin> </plugins> </build> </project>
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<string> 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<string> res = new HashMap(); res.put("code",0); res.put("desc","success"); res.put("data",data); return res.toString(); } private String fail(){ Map<string> res = new HashMap(); res.put("code",1); res.put("desc","fail"); return res.toString(); } }</string></string></string>
Enter: mvn clean package
, (몇 분 정도 걸릴 수 있음), 로컬 저장소를 지정하는 것이 가장 좋습니다. 빌드하기 전에 jar 패키지를 다시 다운로드할 필요가 없습니다.
소켓 포트 = 8081을 지정하고 디버깅할 모듈을 지정하세요
b에서 디버그를 시작합니다. 그런 다음 터미널에 java -agentlib:jdwp=transport=dt_socket,server=n,address=localhost:8081 -jar remote_test-0.0 명령을 입력합니다. 1-SNAPSHOT- all.jar
5. Test
참고: 먼저 IDEA에서 디버그를 시작한 다음 시작해야 합니다. 프로젝트
➜ 데스크톱 java -agentlib:jdwp=transport=dt_socket,server=n,address=localhost:8081 -jar remote_test-0.0.1-SNAPSHOT-all.jarERROR: 전송 오류 202: 연결 실패: 연결이 거부되었습니다.
ERROR: JDWP 전송 dt_socket을 초기화하지 못했습니다. TRANSPORT_INIT(510)
JDWP 종료 오류 AGENT_ERROR_TRANSPORT_INIT(197): 초기화된 전송이 없습니다. [debugInit.c:750]
위 내용은 springboot에서 IDEA 원격 연결 디버그를 사용하는 방법의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!