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容器相关的启动 一.不 ...
随机推荐
- golang微服务框架go-micro 入门笔记1.搭建 go-micro环境
微服务的本质是让专业的人做专业的事情,做出更好的东西. golang具备高并发,静态编译等特性,在性能.安全等方面具备非常大的优势.go-micro是基于golang的微服务编程框架,go-micro ...
- linux初学者-编辑文件工具vim
"vim"是linux中非常强大,应用非常广的编辑方式.下面介绍一些"vim"的基本用法.以"/etc/passwd"为例. 1.vim ...
- oracle 数据库触发器,插入更新时间戳
1.首先建立一个测试表 CREATE TABLE TestTragger( UserId int Primary Key, Name VARCHAR() Not Null, CreateTime Ti ...
- Oracle与SQL Server等数据库的区别
Oracle与SQL Server等数据库的区别 在Oracle中提倡使用一个连接 Oracle处理多个并发语句使用一个连接,大大提升系统能支持的并发量 Oracle运行在32为单进程平台上SGA和P ...
- jquery实现弹出层完美居中效果
代码如下: showDiv($("#pop"));function showDiv(obj){ $(obj).show(); center(obj); $(window).scro ...
- jstorm了解—应用场景
JStorm处理数据的方式是基于消息的流水线处理, 因此特别适合无状态计算,也就是计算单元的依赖的数据全部在接受的消息中可以找到, 并且最好一个数据流不依赖另外一个数据流. 因此,常常用于: 日志分析 ...
- Maven的SNAPSHOT版本找不到
有时一个SNAPSHOT版本的包,明明打包部署到私服了,却还是报错找不到,比如: [WARNING] The POM for com.foo:bar:jar:0.4.0-20130404.093655 ...
- MYSQL5.7生成列简介及创建
1.说明 生成列是由已存在的字段通过表达式计算得来的 2.生成列类型 VIRTUAL,即虚拟类型,字段值不实际存储,当读取行时再计算,虚拟列类型不占存储 STORED,即存储类型,字段值会实际存储起来 ...
- Apache 正向代理与反向代理配置
Apache提供了 mod_proxy 模块用于提供代理服务,能够支持的包括正向代理.反向代理.透明代理.缓存.负载均衡,HTTP代理.FTP代理.SSL代理等若干强大的功能. 配置代理方法很简单那, ...
- Linux DHCP 中继
具体到一个公司的网络环境中,不可能只有一个VLAN,更不可能对每个VLAN都架设一个DHCP服务器,这时就要做一个DHCP的中继,使得DHCP的广播可以通过VLAN. 实验拓扑 三层交换机下面连接一台 ...