SpringBoot2.2.13源码调试
一、源码调试环境搭建验证
1、修改源码包中的pom.xml的配置
<properties>
<!--建议修改 Springboot的版本号,避免和官方版本号产生冲突-->
<revision>2.2.13.RELEASE.aibei</revision>
<main.basedir>${basedir}</main.basedir>
<!--这个配置:关闭Maven代码检查-->
<disable.checks>true</disable.checks>
</properties>
2、重新编译源码项目
-
mvn clean install -DskipTests -Pfast
-
[INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 04:26 min [INFO] Finished at: 2024-04-05T10:12:37+08:00 [INFO] ------------------------------------------------------------------------ [INFO] 1266 goals, 1130 executed, 136 from cache, saving at least 13s [INFO] [INFO] A build scan was not published as you have not authenticated with server 'ge.spring.io'.
3、新建一个module用户源码调试
*
-
修改pom文件
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://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.2.13.RELEASE.aibei</version> <relativePath/> <!-- lookup parent from repository --> </parent> <groupId>com.ai_bei</groupId> <artifactId>springboot-ai-bei-tests</artifactId> <version>1.0-SNAPSHOT</version> <properties> <maven.compiler.source>17</maven.compiler.source> <maven.compiler.target>17</maven.compiler.target> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> </dependencies> </project>
4、新建Controller接口验证源码调试接口
package com.aibei.springboot.test.controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* Copyright (C), 2010-2023
* FileName: TestController
* Author: shine
* Date: 2024/4/5 10:29
* Description:
* History:
* <author> <time> <version> <desc>
* 作者姓名 修改时间 版本号 描述
*/
@RestController
public class TestController {
@GetMapping("/test")
public String test(){
return "Success";
}
}
5、启动项目验证
package com.aibei.springboot;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/**
* Copyright (C), 2010-2023
* FileName: SpringbootAIBeiTestApplications
* Author: shine
* Date: 2024/4/5 10:32
* Description:
* History:
* <author> <time> <version> <desc>
* 作者姓名 修改时间 版本号 描述
*/
@SpringBootApplication
public class SpringbootAIBeiTestApplication {
public static void main(String[] args) {
SpringApplication.run(SpringbootAIBeiTestApplication.class, args);
}
}
## 通过 curl 访问接口验证
PS C:\Users\shine> curl http://localhost:8080/test
StatusCode : 200
StatusDescription :
Content : Success
RawContent : HTTP/1.1 200
Keep-Alive: timeout=60
Connection: keep-alive
Content-Length: 7
Content-Type: text/plain;charset=UTF-8
Date: Fri, 05 Apr 2024 02:39:04 GMT
Success
Forms : {}
Headers : {[Keep-Alive, timeout=60], [Connection, keep-alive], [Content-Length, 7], [Content-Type, text/plain;charset=UTF-8]...}
Images : {}
InputFields : {}
Links : {}
ParsedHtml : mshtml.HTMLDocumentClass
RawContentLength : 7