Spring源码解析:获取源码

Spring工程采用Gradle作项目管理,因此咱们须要在本地安装Gradle,个人的本地环境以下:java

Windows 10 Professional
java 1.8.0_102
Gradle 3.4.1
git version 2.11.0

一. 从git上下载源码

$ git clone https://github.com/spring-projects/spring-framework.git
Cloning into 'spring-framework'...
remote: Counting objects: 316377, done.
remote: Compressing objects: 100% (98/98), done.
remote: Total 316377 (delta 34), reused 0 (delta 0), pack-reused 316257
Receiving objects: 100% (316377/316377), 85.40 MiB | 129.00 KiB/s, done.
Resolving deltas: 100% (154808/154808), done.
Checking connectivity... done.
Checking out files: 100% (7366/7366), done.

Spring源码工程一览:git

$ ll
total 93
-rw-r--r-- 1 zhenchao.Wang 197609 36887 8月  21 03:22 build.gradle
drwxr-xr-x 1 zhenchao.Wang 197609     0 8月  21 03:17 buildSrc/
-rw-r--r-- 1 zhenchao.Wang 197609 11483 8月  21 03:22 CONTRIBUTING.md
drwxr-xr-x 1 zhenchao.Wang 197609     0 8月  21 03:22 gradle/
-rw-r--r-- 1 zhenchao.Wang 197609    31 8月  21 03:22 gradle.properties
-rwxr-xr-x 1 zhenchao.Wang 197609  5304 8月  21 03:22 gradlew*
-rw-r--r-- 1 zhenchao.Wang 197609  2487 8月  21 03:22 gradlew.bat
-rw-r--r-- 1 zhenchao.Wang 197609  4140 8月  21 03:22 import-into-eclipse.bat
-rw-r--r-- 1 zhenchao.Wang 197609  3560 8月  21 03:22 import-into-eclipse.sh
-rw-r--r-- 1 zhenchao.Wang 197609  1376 8月  21 03:22 import-into-idea.md
-rw-r--r-- 1 zhenchao.Wang 197609  4906 8月  21 03:22 README.md
-rw-r--r-- 1 zhenchao.Wang 197609   786 8月  21 03:22 settings.gradle
drwxr-xr-x 1 zhenchao.Wang 197609     0 8月  21 03:17 spring-aop/
drwxr-xr-x 1 zhenchao.Wang 197609     0 8月  21 03:22 spring-aspects/
drwxr-xr-x 1 zhenchao.Wang 197609     0 8月  21 03:17 spring-beans/
drwxr-xr-x 1 zhenchao.Wang 197609     0 8月  21 03:17 spring-context/
drwxr-xr-x 1 zhenchao.Wang 197609     0 8月  21 03:17 spring-context-support/
drwxr-xr-x 1 zhenchao.Wang 197609     0 8月  21 03:17 spring-core/
drwxr-xr-x 1 zhenchao.Wang 197609     0 8月  21 03:17 spring-expression/
drwxr-xr-x 1 zhenchao.Wang 197609     0 8月  21 03:22 spring-framework-bom/
drwxr-xr-x 1 zhenchao.Wang 197609     0 8月  21 03:17 spring-instrument/
drwxr-xr-x 1 zhenchao.Wang 197609     0 8月  21 03:22 spring-instrument-tomcat/
drwxr-xr-x 1 zhenchao.Wang 197609     0 8月  21 03:17 spring-jdbc/
drwxr-xr-x 1 zhenchao.Wang 197609     0 8月  21 03:17 spring-jms/
drwxr-xr-x 1 zhenchao.Wang 197609     0 8月  21 03:17 spring-orm/
drwxr-xr-x 1 zhenchao.Wang 197609     0 8月  21 03:22 spring-orm-hibernate4/
drwxr-xr-x 1 zhenchao.Wang 197609     0 8月  21 03:22 spring-oxm/
drwxr-xr-x 1 zhenchao.Wang 197609     0 8月  21 03:22 spring-struts/
drwxr-xr-x 1 zhenchao.Wang 197609     0 8月  21 03:22 spring-test/
drwxr-xr-x 1 zhenchao.Wang 197609     0 8月  21 03:22 spring-test-mvc/
drwxr-xr-x 1 zhenchao.Wang 197609     0 8月  21 03:17 spring-tx/
drwxr-xr-x 1 zhenchao.Wang 197609     0 8月  21 03:17 spring-web/
drwxr-xr-x 1 zhenchao.Wang 197609     0 8月  21 03:17 spring-webmvc/
drwxr-xr-x 1 zhenchao.Wang 197609     0 8月  21 03:22 spring-webmvc-portlet/
drwxr-xr-x 1 zhenchao.Wang 197609     0 8月  21 03:22 spring-webmvc-tiles3/
drwxr-xr-x 1 zhenchao.Wang 197609     0 8月  21 03:23 src/

二. 构建工程

2.1 导入eclipse工程

第一步,运行import-into-eclipse.bat,双击运行便可,Linux系统运行运行import-into-eclipse.shgithub

-----------------------------------------------------------------------
Spring Framework Eclipse/STS project import guide
This script will guide you through the process of importing the
Spring Framework sources into Eclipse/STS. It is recommended that you
have a recent version of the SpringSource Tool Suite (this script has
been tested against STS '2.9.2.RELEASE'), but at the minimum you will
need Eclipse + AJDT.

If you need to download and install STS, please do that now by
visiting http://springsource.org/downloads/sts

Otherwise, press enter and we will begin.
Press any key to continue. . .

-----------------------------------------------------------------------
STEP 1: Generate subproject Eclipse metadata

The first step will be to generate Eclipse project metadata for each
of the spring-* subprojects. This happens via the built-in
"Gradle wrapper" script (./gradlew in this directory). If this is your
first time using the Gradle wrapper, this step may take a few minutes
while a Gradle distribution is downloaded for you.

The command run will be:

    gradlew cleanEclipse :spring-oxm:compileTestJava eclipse -x :eclipse

Press enter when ready.
Press any key to continue. . .

第二步,导入到eclipse,按照提示的步骤操做便可:web

-----------------------------------------------------------------------
STEP 2: Import subprojects into Eclipse/STS
Within Eclipse/STS, do the following:
File > Import... > Existing Projects into Workspace
     > When prompted for the 'root directory', provide E:\dev_workspace\git\zhenchao\java\workspace\eclipse\spring-framework\
     > Press enter. You will see the modules show up under "Projects"
     > All projects should be selected/checked. Click Finish.
     > When the project import is complete, you should have no errors.
When the above is complete, return here and press the enter key.

2.2 导入IntelliJ工程

第一步,在项目的spring-framework/spring-oxm目录下,执行./gradle cleanIdea :spring-oxm:compileTestJavaspring

$ gradle cleanIdea :spring-oxm:compileTestJava
Starting a Gradle Daemon (subsequent builds will be faster)
Generating JAR file 'gradle-api-3.4.1.jar'
:buildSrc:clean UP-TO-DATE
:buildSrc:compileJava NO-SOURCE
:buildSrc:compileGroovy
:buildSrc:processResources
:buildSrc:classes
:buildSrc:jar
:buildSrc:assemble
:buildSrc:compileTestJava NO-SOURCE
:buildSrc:compileTestGroovy NO-SOURCE
:buildSrc:processTestResources NO-SOURCE
:buildSrc:testClasses UP-TO-DATE
:buildSrc:test NO-SOURCE
:buildSrc:check UP-TO-DATE
:buildSrc:build

......

Download https://repo.spring.io/libs-release/org/codehaus/jettison/jettison/1.3.8/jettison-1.3.8.pom
Download https://repo.spring.io/libs-release/org/codehaus/jettison/jettison/1.3.8/jettison-1.3.8.jar
:spring-oxm:compileTestJava
Download https://repo.spring.io/libs-release/org/jibx/jibx-bind/1.2.6/jibx-bind-1.2.6.pom
Download https://repo.spring.io/libs-release/org/apache/bcel/bcel/6.0/bcel-6.0.pom
Download https://repo.spring.io/libs-release/org/apache/apache/17/apache-17.pom
Download https://repo.spring.io/libs-release/log4j/log4j/1.2.17/log4j-1.2.17.pom
Download https://repo.spring.io/libs-release/org/codehaus/codehaus-parent/4/codehaus-parent-4.pom
Download https://repo.spring.io/libs-release/org/jibx/jibx-bind/1.2.6/jibx-bind-1.2.6.jar
Download https://repo.spring.io/libs-release/org/apache/bcel/bcel/6.0/bcel-6.0.jar
:spring-oxm:copyTestKotlinClasses

BUILD SUCCESSFUL

Total time: 8 mins 23.728 secs

第二步,导入IntelliJ工程:express

File -> New -> Project from Existing Sources -> Navigate to directory -> Select build.gradleapache

系列文章

  1. Spring源码解析:获取源码
  2. Spring源码解析:资源的描述与加载
  3. Spring源码解析:IoC容器的基本结构设计
  4. Spring源码解析:简单容器中Bean的加载过程初探
  5. Spring源码解析:默认标签的解析过程
  6. Spring源码解析:自定义标签的解析过程
  7. Spring源码解析:Bean实例的建立与初始化
  8. Spring源码解析:高级容器的扩展内幕
  9. Spring源码解析:循环依赖的探测与处理

鉴于做者水平有限,文中难免有错误之处,欢迎你们批评指正~api

同步更新站点:www.zhenchao.orgtomcat

相关文章
相关标签/搜索