本文使用工具如下
这SpringFrame5.1源码阅读环境构建
-
gradle5.1
-
IDEA2021.2
-
JDK1.8
-
SpringFrame5.1
如果是第一次构建SpringFrame源码环境,请严格按照本文给出的这些版本号去尝试
拉取SpringFrame5.1项目
git地址:https://github.com/spring-projects/spring-framework/
git命令输入如下指令:
git clone https://github.com/spring-projects/spring-framework.git
cd spring-framework/
git checkout 5.1.x
项目启动
修改配置
修改build.gradle配置
修改源码的build.gradle文件内容,添加aliyun镜像
maven { url "http://maven.aliyun.com/nexus/content/groups/public" }
修改gradle-wrapper.properties配置
修改gradle-wrapper.properties配置,将gradle的版本提高至gradle5.1
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https://services.gradle.org/distributions/gradle-5.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
然后使用IDEA打开项目。
IDEA设置
安装Kotlin插件
修改JDK编译版本
一共有四个地方需要修改
setting配置:
Project Structure配置:
测试
添加一个自己的module,如下图
构建完成后,选择创建module的build.gradle文件添加spring相关依赖并创建自己想的结构,如下图:
测试类内容(就把他当做简单的Spring项目对待就好了):
package com.edu.client.mainclient;
import com.edu.client.config.SpringClientConfig;
import com.edu.client.pojo.Student;
import com.edu.client.service.StudentService;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import java.util.List;
public class ClientTest01 {
public static void main(String[] args) {
AnnotationConfigApplicationContext annotationConfigApplicationContext =
new AnnotationConfigApplicationContext(SpringClientConfig.class);
StudentService studentService = annotationConfigApplicationContext.getBean(StudentService.class);
Student student = annotationConfigApplicationContext.getBean(Student.class);
List<Student> studentList = studentService.getStudentList();
studentList.forEach(System.out::println);
System.out.println(student);
}
}
如下图就是成功了,如图: