SpringBoot源码分析-编译环境与新建测试模块
建议
分析源码建议不要使用Idea或者Eclipse等IDE工具的反编译功能或者导入源码包的方式看源码,那样不能给框架的源码做注释,所以分析源码之前都得先下载源码并构建,然后在项目中新建一个Module看代码是否能够正常启动与运行。
另外因为博客是在看源码后写的,我自己看的源码版本是2.1.X,这里演示的2.2.X,方法和2.1.X是一样的。
备注:无意中发现一个比较优质的博客:https://blog.csdn.net/qq_26000415/article/list/7,速览了一下他的文章列表,都是挺高级的货,推广一下(当然每个博主写的文章都可能有误,建议大家在阅读的时候一定要自己验证)
官方BUILD SOURCE建议
下面这段英文对于想要快速构建编译环境的同学就不要尝试了,因为它会下载一个Maven,使用默认的配置重新下载一些依赖包,下载Maven耗时,下载你之前已经下载过的包更耗时。。。但是它有应该有一个优点简单一步构建成功,否则就不是官方文档。
You don’t need to build from source to use Spring Boot (binaries in repo.spring.io), but if you want to try out the latest and greatest, Spring Boot can be easily built with the maven wrapper. You also need JDK 1.8.
$ ./mvnw clean install
If you want to build with the regular mvn command, you will need Maven v3.5.0 or above.
| Note | You may need to increase the amount of memory available to Maven by setting a MAVEN_OPTS environment variable with the value -Xmx512m. Remember to set the corresponding property in your IDE as well if you are building and running tests there (e.g. in Eclipse go to Preferences→Java→Installed JREs and edit the JRE definition so that all processes are launched with those arguments). This property is automatically set if you use the maven wrapper. |
|---|---|
Also see CONTRIBUTING.adoc if you wish to submit pull requests, and in particular please fill out the Contributor’s Agreement before your first change, however trivial.
Building reference documentation
First of all, make sure you have built the project:
$ ./mvnw clean install
The reference documentation requires the documentation of the Maven plugin to be available so you need to build that first since it’s not generated by default.
$ ./mvnw clean install -pl spring-boot-project/spring-boot-tools/spring-boot-maven-plugin -Pdefault,full
The documentation also includes auto-generated information about the starters. You might have that in your local repository already (per the first step) but if you want to refresh it:
$ ./mvnw clean install -f spring-boot-project/spring-boot-starters
Once this is done, you can build the reference documentation with the command below:
$ ./mvnw clean prepare-package -pl spring-boot-project/spring-boot-docs -Pdefault,full
使用已有Maven构建
下载
地址:https://github.com/spring-projects/spring-boot/tree/2.2.x

修改Maven配置
有的同学从来没有使用过Maven命令行编译过代码,那么使用命令行编译,Maven读取的还是Maven自己目录下的setting.xml文件,所以要修改里面的内容
修改1,将Maven本地仓库目录修改为IDE工具中Maven本地仓库目录,比如:
<localRepository>F:\data\maven\repository</localRepository>
修改2:为了能更快的下载,可以将配置文件中的Maven仓库镜像设置为阿里云的
<mirrors>
<!-- 阿里云仓库 central-->
<mirror>
<id>alimaven</id>
<mirrorOf>central</mirrorOf>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/repositories/central/</url>
</mirror>
<!-- 中央仓库1 -->
<mirror>
<id>repo1</id>
<mirrorOf>central</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>http://repo1.maven.org/maven2/</url>
</mirror>
<!-- 中央仓库2 -->
<mirror>
<id>repo2</id>
<mirrorOf>central</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>http://repo2.maven.org/maven2/</url>
</mirror>
<!-- 阿里云的maven-public路径 -->
<mirror>
<id>nexus-aliyun</id>
<mirrorOf>*</mirrorOf>
<name>Nexus aliyun</name>
<url>http://maven.aliyun.com/nexus/content/groups/public</url>
</mirror>
</mirrors>
如果嫌这个比较麻烦,直接将自己IDE中指定的setting.xml文件覆盖MAVEN_HOME/conf/setting.xml
构建
使用命令构建,使用skipTests跳过SpringBoot中的测试,
mvn clean install -DskipTests -Pfast
整个构建过程花的时间比较长,我自己使用了1小时53分钟,构建成功的结果页

导入项目
打开Idea,选择File-open file-选择构建成功目录下pom.xml,然后选择open as project选项

最后等待导入成功

新建测试工程
在spring-boot-project目录下新建一个工程

在main目录下新建一个resources目录,并标记为“Resources root”

导入spring-boot-starter-web依赖
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.2.3.BUILD-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
新建启动类和Controller
@SpringBootApplication
public class BootApplication {
public static void main(String[] args) {
SpringApplication.run(BootApplication.class,args);
}
}
@RestController
public class UserController {
@RequestMapping("/query")
public User query(){
return new User("Messi",33);
}
}
@Setter
@Getter
public class User {
private String userName;
private Integer age;
public User(){}
public User(String userName,Integer age){
this.userName=userName;
this.age=age;
}
}
启动-测试

那么恭喜,接下来就可以开始分析源码之旅了
来源:沈阳网站优化
SpringBoot源码分析-编译环境与新建测试模块的更多相关文章
- 鸿蒙内核源码分析(编译环境篇) | 编译鸿蒙看这篇或许真的够了 | 百篇博客分析OpenHarmony源码 | v50.06
百篇博客系列篇.本篇为: v50.xx 鸿蒙内核源码分析(编译环境篇) | 编译鸿蒙防掉坑指南 | 51.c.h.o 编译构建相关篇为: v50.xx 鸿蒙内核源码分析(编译环境篇) | 编译鸿蒙防掉 ...
- 鸿蒙内核源码分析(编译脚本篇) | 如何防编译环境中的牛皮癣 | 百篇博客分析OpenHarmony源码 | v58.01
百篇博客系列篇.本篇为: v58.xx 鸿蒙内核源码分析(环境脚本篇) | 编译鸿蒙原来如此简单 | 51.c.h.o 本篇用两个脚本完成鸿蒙(L1)的编译环境安装/源码下载/编译过程,让编译,调试鸿 ...
- 鸿蒙内核源码分析(编译过程篇) | 简单案例窥视GCC编译全过程 | 百篇博客分析OpenHarmony源码| v57.01
百篇博客系列篇.本篇为: v57.xx 鸿蒙内核源码分析(编译过程篇) | 简单案例窥视编译全过程 | 51.c.h.o 编译构建相关篇为: v50.xx 鸿蒙内核源码分析(编译环境篇) | 编译鸿蒙 ...
- SpringBoot源码分析之SpringBoot的启动过程
SpringBoot源码分析之SpringBoot的启动过程 发表于 2017-04-30 | 分类于 springboot | 0 Comments | 阅读次数 SpringB ...
- 从SpringBoot源码分析 配置文件的加载原理和优先级
本文从SpringBoot源码分析 配置文件的加载原理和配置文件的优先级 跟入源码之前,先提一个问题: SpringBoot 既可以加载指定目录下的配置文件获取配置项,也可以通过启动参数( ...
- Springboot源码分析之项目结构
Springboot源码分析之项目结构 摘要: 无论是从IDEA还是其他的SDS开发工具亦或是https://start.spring.io/ 进行解压,我们都会得到同样的一个pom.xml文件 4. ...
- zrender源码分析3--初始化Painter绘图模块
接上次分析到初始化ZRender的源码,这次关注绘图模块Painter的初始化 入口1:new Painter(dom, this.storage); // zrender.js /** * ZRen ...
- Spring源码分析——(001)环境搭建
1.官方参考 spring-framework的github链接:https://github.com/spring-projects/spring-framework 源码环境搭建官方参考1:考如何 ...
- SpringBoot源码分析(二)启动原理
Springboot的jar启动方式,是通过IOC容器启动 带动了Web容器的启动 而Springboot的war启动方式,是通过Web容器(如Tomcat)的启动 带动了IOC容器相关的启动 一.不 ...
随机推荐
- cisco ap客户端无规律掉线
设备 cisco air-ct2504-50-k9 cisco air-ap1832I-H-k9 首先根据这个帖子 https://community.cisco.com/t5/other-wirel ...
- 004 Thymeleaf学习笔记
1.Thymeleaf概述 SpringBoot并不推荐使用jsp,但是支持一些模板引擎技术:Freemarker.Thymeleaf.Mustache. 简单说, Thymeleaf 是一个跟 Ve ...
- 手撕面试官系列(六):并发+Netty+JVM+Linux面试专题
并发面试专题 (面试题+答案领取方式见侧边栏) 现在有 T1.T2.T3 三个线程,你怎样保证 T2 在 T1 执行完后执行,T3 在 T2 执行完后执行? 在 Java 中 Lock 接口比 syn ...
- js确定取消—js确定取消判断
国瑞前端: js确定取消,在html界面中,有css模拟的模态框,这样显示的就会更好看一些,那么javascript有没有自带的弹框呢,当然是有的,接下来我就来给大家介绍一下把: js确定取消-警告框 ...
- Python 基础 编码
Python 基础 编码 咱们的电脑,存储和发送文件,发送的是什么?电脑里面是不是有成千上万个二极管,亮的代表是1,不亮的代表是0,这样实际上电脑的存储和发送是不是都是010101啊 我们发送的内容都 ...
- Solved:Spring Junit Test NoSuchMethodError
最近在看Spring in action这本书,在Ubuntu上配好了环境开始开发,没想到做了第二章的第一个例子就遇到了一个错误. 首先我在src/main/java文件夹下的controller包内 ...
- golang 之 sql
golang提供了sql包查询数据 建立连接 导入第三方包 import( "database/sql" _"github.com/go-sql-driver/mysql ...
- 线程池及Executor框架
1.为什么要使用线程池? 诸如 Web 服务器.数据库服务器.文件服务器或邮件服务器之类的许多服务器应用程序都面向处理来自某些远程来源的大量短小的任务.请求以某种方式到达服务器,这种方式可能是通过 ...
- php中的for循环和js中的for循环
php中的for循环 循环100个0 for ($i=0;$i<=100;$i++){ $pnums.='0'.","; } js中的for循环,循环31个相同的数.循环日期 ...
- Teamviewer显示“未就绪,请检查您的连接”解决办法
打开TeamViewer一直提示“未就绪,请检查您的连接”,一直会弹出一个框提示检查网路设置什么. 解决办法:修改DNS为114.114.114.114,然后TeamViewer就显示网络正常. 为什 ...