Idea 如何搭建Spring源码环境
创始人
2024-11-16 16:01:51
0次

1. clone spring-framework 项目

1.1 找到github spring-framwwork 项目

先登录github 找到 spring-framework项目

https://github.com/spring-projects

Idea 如何搭建Spring源码环境

我选择的是 5.0.x

Idea 如何搭建Spring源码环境

如果你觉得你网速可以,那你可以直接从 github clone 下来, 我这里先把项目传到 gitee

1.2 fork 到gitee 码云

Idea 如何搭建Spring源码环境

拉取你要的 分支 git clone -b 分支

Idea 如何搭建Spring源码环境

2. 查看 import-into-idea.md 文件

在下载的源码中 有一个文件是 import-into-idea 的 md文件 里面有关于导入 idea需要的 注意事项,我们来打开它

The following has been tested against IntelliJ IDEA 2016.2.2

## Steps

_Within your locally cloned spring-framework working directory:_

1. Precompile `spring-oxm` with `./gradlew :spring-oxm:compileTestJava`
2. Import into IntelliJ (File -> New -> Project from Existing Sources -> Navigate to directory -> Select build.gradle)
3. When prompted exclude the `spring-aspects` module (or after the import via File-> Project Structure -> Modules)
4. Code away

## Known issues

1. `spring-core` and `spring-oxm` should be pre-compiled due to repackaged dependencies.
See `*RepackJar` tasks in the build and https://youtrack.jetbrains.com/issue/IDEA-160605).
2. `spring-aspects` does not compile due to references to aspect types unknown to
IntelliJ IDEA. See https://youtrack.jetbrains.com/issue/IDEA-64446 for details. In the meantime, the
'spring-aspects' can be excluded from the project to avoid compilation errors.
3. While JUnit tests pass from the command line with Gradle, some may fail when run from
IntelliJ IDEA. Resolving this is a work in progress. If attempting to run all JUnit tests from within
IntelliJ IDEA, you will likely need to set the following VM options to avoid out of memory errors:
 -XX:MaxPermSize=2048m -Xmx2048m -XX:MaxHeapSize=2048m
4. If you invoke "Rebuild Project" in the IDE, you'll have to generate some test
resources of the `spring-oxm` module again (`./gradlew :spring-oxm:compileTestJava`) 


## Tips

In any case, please do not check in your own generated .iml, .ipr, or .iws files.
You'll notice these files are already intentionally in .gitignore. The same policy goes for eclipse metadata.

## FAQ

Q. What about IntelliJ IDEA's own [Gradle support](https://confluence.jetbrains.net/display/IDEADEV/Gradle+integration)?

A. Keep an eye on https://youtrack.jetbrains.com/issue/IDEA-53476

大致意思就是

2.1 在源码目录下执行

 ./gradlew :spring-oxm:compileTestJava

Idea 如何搭建Spring源码环境

Idea 如何搭建Spring源码环境

2.2 再导入导 idea 中

会开始下载 Gradle 构建工具 等,会根据 gradle-wrapper.properties 中的指定版本下载,最好不要修改它的版本

Idea 如何搭建Spring源码环境

Idea导入 选择文件夹

Idea 如何搭建Spring源码环境

选择使用Gradle

![image-20200924103346932](/Users/johnny/Library/Application Support/typora-user-images/image-20200924103346932.jpg)

静静的等待

Idea 如何搭建Spring源码环境

Idea 如何搭建Spring源码环境

2.3 排除 "spring-aspects"

排除了 spring-aspects 项目

打开settings.gradle 把 //include "spring-aspects" 注释了

Idea 如何搭建Spring源码环境

2.4 下载完依赖后 (耗时可能要个15-30分钟)

可以发现 依赖都加载完成后,idea 就能识别我们导入的 spring项目了,并且图标都变亮了

Idea 如何搭建Spring源码环境

3.引入自定义模块放入SpringFramework 项目下

下面就是来验证 我们的 源码环境是否 正常, 需要引入一个自定义的 模块,并且依赖 core bean 等spring依赖

3.1 新建module

右击项目 -》 new -》 module 选择 gradle 项目

Idea 如何搭建Spring源码环境

3.2 添加 依赖

在新建的module下 打开 build.gradle 引入下面的依赖 spring-beans , spring-context , spring-core , spring-expression

dependencies {
 testCompile group: 'junit', name: 'junit', version: '4.12'

 compile(project(":spring-beans"))
 compile(project(":spring-context"))
 compile(project(":spring-core"))
 compile(project(":spring-expression"))
}

3.3 检查 module 是否被引入

打开settings.gradle 添加 include 'spring-demo' ,默认使用我说的创建module 方式 会自动添加的最好检查一下

3.4 编写 测试代码

3.4.1 定义Person类

package com.johnny.bean;

/**
 * @author johnny
 * @create 2020-09-07 下午11:22
 **/
public class Person {

 private String name;

 private int age;

 @Override
 public String toString() {
 return "Person{" +
  "name='" + name + '\'' +
  ", age=" + age +
  '}';
 }

 public String getName() {
 return name;
 }

 public void setName(String name) {
 this.name = name;
 }

 public int getAge() {
 return age;
 }

 public void setAge(int age) {
 this.age = age;
 }
}

3.4.2 resources 下新建 demo.xml

<?xml version="1.0" encoding="UTF-8"?>



 
 
 
 

3.4.3 新建main 加载xml 并且从容器中获取 bean

package com.johnny.bean;

import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * @author johnny
 * @create 2020-09-07 下午11:24
 **/
public class DemoMain {

 public static void main(String[] args) {
 ClassPathXmlApplicationContext classPathXmlApplicationContext = new ClassPathXmlApplicationContext("demo.xml");
 Person person = classPathXmlApplicationContext.getBean(Person.class);
 System.out.println(person);
 }
}

相关内容

热门资讯

空调连续工作多久需要停机休息 空调连续工作的时间取决于多个因素,包括空调的型号、功率、使用环境和维护情况等。一般来说,空调可以连续...
空调哪个符号是除湿的 空调除湿功能通常用一个水滴形状的符号表示。不同品牌和型号的空调遥控器可能会有所差异,但一般来说,除湿...
格力空调多长时间加一次氟利昂 1、一般情况下,空调对氟利昂的使用量是非常小的,所以在空调使用了四年左右的时候再考虑加也没问题。2、...
空调用多长时间需要加氟一次 一般情况下是五年。当出现以下这几种情况时,空调才需要加氟。1、空调的室内机和室外机各有两个接口,当接...
格调生活·C标思享荟:卡萨帝在... 9月12日的郑州龙湖金融岛,夜风轻拂,灯光璀璨。“C标时刻共传奇——卡萨帝思享荟暨20周年品牌盛典郑...
品牌价值破千亿、高端份额持续领... 9月12日,“C标时刻共传奇——卡萨帝思享荟暨20周年品牌盛典郑州站”在郑州龙湖金融岛举办。2026...
空调主板坏了修800还是换新的 空调主板坏了是修还是换新,需要考虑多个因素,以下是一些建议:1. 维修成本:如果维修费用较低,比如 ...
空调开多久需要休息多长时间 问题:空调开多久需要休息多长时间回答:1、在使用空调的过程中,一般空调开7~8个小时左右需要休息2~...
中央空调多长时间清洗一次 1、一般空调开机前清洗一次即可,空调开机中间时段再清洗一次,空调关机时清洗一次,这样比较合理。2、空...
中央空调氟利昂多久加一次 看空调制热和制冷程度,很多人的观点认为氟利昂必须一年放一次,其实这个观点是错误的,理解上面有点偏差,...