java如何导入spring源码_Spring源码导入Eclipse

本文详细介绍了如何将Spring源码导入Eclipse进行阅读:从下载源码到配置Gradle、JDK,再到安装Kotlin和Groovy插件,以及修改Eclipse的编译设置。最后通过Gradlew命令行工具准备源码导入,确保所有必要步骤完成后,即可在Eclipse中愉快地阅读和理解Spring的源码。
摘要由CSDN通过智能技术生成

最近开始阅读 Spring 源码,一步步教大家我是如何阅读的。

1.下载源文件

2.编译

参考 import-into-eclipse.md 文件进行导入工程

2.1 下载安装好 gradle 然后配置 gradle 环境变量,执行 gradlew.bat 我的目录是 I:\mygit\java\spring-framework-src

AAffA0nNPuCLAAAAAElFTkSuQmCC

2.2 确保 eclipse 使用的 JDK8 以上的

2.3 安装 [Kotlin Plugin for Eclipse] 打开Eclipse,使用Help -> Eclipse Marketplace… 菜单,搜索 Kotlin 插件,并安装

AAffA0nNPuCLAAAAAElFTkSuQmCC

2.4 安装 [Eclipse Groovy Development Tools] ,查找自己 eclipse 版本 help->About Eclipse

AAffA0nNPuCLAAAAAElFTkSuQmCC

2.5 打开eclipse,在eclipse中,选择help -> Install New Software… 粘贴地址,全选并下一步,进行安装

AAffA0nNPuCLAAAAAElFTkSuQmCC

2.6 在 Eclipse 中转换 Groovy 2.5 (Preferences -> Groovy -> Compiler -> Switch to 2.5…)

AAffA0nNPuCLAAAAAElFTkSuQmCC

2.7 修改参数

(Preferences -> Java -> Compiler -> Errors/Warnings -> Deprecated and restricted API -> Forbidden reference (access rule)).

AAffA0nNPuCLAAAAAElFTkSuQmCC

2.8 (可选择)如果需要 spring-aspects 项目.安装 AspectJ Development Tools (AJDT)

2.9 通过命令行 ./gradlew :spring-oxm:check.构建 spring-oxm

AAffA0nNPuCLAAAAAElFTkSuQmCC

3.0 命令行执行 ./gradlew eclipseBuildship

AAffA0nNPuCLAAAAAElFTkSuQmCC

3.导入 Eclipse

(File -> Import -> Existing Projects into Workspace -> Select root directory -> Browse spring-framework-src directory -> Select Finish).

阅读

然后我们就可以愉快的开始阅读源码了……确实很枯燥的源码,建议结合书还有 Demo 代码来理解其中的含义,代码量还是蛮多的,而且,注释基本都英文的,所以想学好代码,英语还是不能差的。

原文步骤:Steps

When instructed to execute ./gradlew from the command line, be sure to execute it within your locally cloned spring-framework working directory.

Ensure that Eclipse launches with JDK 8.

For example, on Mac OS this can be configured in the Info.plist file located in the Contents folder of the installed Eclipse or STS application (e.g., the Eclipse.app file).

Switch to Groovy 2.5 (Preferences -> Groovy -> Compiler -> Switch to 2.5…) in Eclipse.

Change the Forbidden reference (access rule) in Eclipse from Error to Warning

(Preferences -> Java -> Compiler -> Errors/Warnings -> Deprecated and restricted API -> Forbidden reference (access rule)).

Optionally install the AspectJ Development Tools (AJDT) if you need to work with the spring-aspects project.

Optionally install the TestNG plugin in Eclipse if you need to execute TestNG tests in the spring-test module.

Build spring-oxm from the command line with ./gradlew :spring-oxm:check.

To apply project specific settings, run ./gradlew eclipseBuildship from the command line.

Import into Eclipse (File -> Import -> Gradle -> Existing Gradle Project -> Navigate to the locally cloned spring-framework directory -> Select Finish).

If you have not installed AJDT, exclude the spring-aspects project from the import, if prompted, or close it after the import.

If you run into errors during the import, you may need to set the Java home for Gradle Buildship to the location of your JDK 8 installation in Eclipse (Preferences -> Gradle -> Java home).

If you need to execute JAXB-related tests in the spring-oxm project and wish to have the generated sources available, add the build/generated-sources/jaxb folder to the build path (right click on the jaxb folder and select Build Path -> Use as Source Folder).

If you do not see the build folder in the spring-oxm project, ensure that the “Gradle build folder” is not filtered out from the view. This setting is available under “Filters” in the configuration of the Package Explorer (available by clicking on the small downward facing arrow in the upper right corner of the Package Explorer).

Code away!

总结

Spring 最主要的是理解 Bean 的概念,理解 AOP 、 IOC,最好是结合实际的代码,而不是只看源码。

1024,程序员们要加油鸭!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值