Spring IoC 源码解析:获取源码

Spring工程采用 Gradle 做项目管理,所以我们需要在本地安装 Gradle,我的的本地环境如下:

  • Windows 10 Professional
  • java 1.8.0_102
  • Gradle 3.4.1

一. 从git上下载源码

1
2
3
4
5
6
7
8
9
$ 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 源码工程一览:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
$ 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.sh

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
-----------------------------------------------------------------------
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,按照提示的步骤操作即可:

1
2
3
4
5
6
7
8
9
-----------------------------------------------------------------------
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 工程

第一步,在项目根目录下执行 ./gradlew cleanIdea :spring-oxm:compileTestJava

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
$ 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 工程:

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


转载声明 : 版权所有,商业转载请联系作者,非商业转载请注明出处
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议
Powered by hexo & Theme by hiero   Copyright © 2015-2019 浙ICP备 16010916  号,指 · 间 All Rights Reserved.