spring如今把源碼都託管到了github上,經過spring的官網找到spring framework 項目,而後找到github便可,也能夠直接點擊下面連接java
https://github.com/spring-projects/spring-framework/tree/4.2.x 而後點擊 DownloadZIP按鈕,下載到本身電腦的相關目錄,而後解壓文件git
好久沒有下載spring源碼了。下載下來看到項目的結構有所改變,如今項目的結構有所不一樣,spring用Gradle進行打包和繼承項目,Gradle集成了Ant Maven的功能,對於不瞭解它的本身搜索一下便可。github
步驟:web
一、所需工具spring
JDK1.8 gradle,eclipse或者spring提供的eclisep/STS(https://spring.io/tools)windows
二、windows下項目導入步驟websocket
下載好Gradle以後,配置Gradle的環境變量,系統環境變量中path指向Gradle解壓後的bin目錄app
解壓下載好的spring代碼eclipse
在解壓目錄中運行 import-into-eclipse.bat文件(這時候出現讓輸入任意鍵繼續,兩次,而後開始下載相關依賴,若是失敗,就重複運行這個命令,由於因爲是外國網站,有些下載會失敗)jvm
有時候會出現如下錯誤
The command run will be: gradlew --no-daemon cleanEclipse :spring-oxm:compileTestJava eclipse -x :ecl ipse Press enter when ready. 請按任意鍵繼續. . . Unrecognized VM option 'MaxMetaspaceSize=1024m' Error: Could not create the Java Virtual Machine. Error: A fatal exception has occurred. Program will exit. ----------------- 這是由於MaxMetaspaceSize=1024m 這個屬性jvm不認識,這時候能夠修改下載下的源碼的gradlew.bat 文件,把MaxMetaspaceSize=1024m這一行給刪除掉 而後從新運行import-into-eclipse.bat ---------------------- 修正一下,上面解決方案是錯誤的。這是由於MaxMetaspaceSize 這個是jdk8中新增長的jvm配置,用於取代永久代設置(XX:MaxPermSize) 因此上述錯誤是jdk版本不對所致使, 能夠在gradlew.bat 文件中把jdk的版本打印出來 set DIRNAME=%~dp0 if "%DIRNAME%" == "" set DIRNAME=. set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% echo ERROR:XXXXXXXXXXXXXXXXXXXXX %JAVA_HOME%/bin/java.exe. 例如XXXX這邊。這樣查看是不是jdk8
完成之後會出現如下畫面
這個步驟完成之後,而後點擊任意鍵繼續,這時候會提示如何把代碼按照提示導入到STS中(打開eclipse-sts,cmd窗口暫時不要動)
按照提示導入完成之後,在eclipse-sts中會有如顯示
而後回到cmd窗口,按照提示完成剩餘步驟便可
這樣咱們就能開始愉快的spring源碼研究之旅啦
我把cmd窗口中的完整輸出顯示出來以下:
D:\open-source\spring-framework-4.2.x-e\spring-framework-4.2.x>import-into-eclipse.bat ----------------------------------------------------------------------- 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://spring.io/tools/sts/all Otherwise, press enter and we'll begin. 請按任意鍵繼續. . . ----------------------------------------------------------------------- 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. 請按任意鍵繼續. . . Downloading https://services.gradle.org/distributions/gradle-1.12-all.zip :spring-websocket:eclipseProject :spring-websocket:eclipseSettings :spring-websocket:eclipseWstComponent :spring-websocket:eclipse BUILD SUCCESSFUL Total time: 23 mins 28.768 secs ----------------------------------------------------------------------- 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 D:\open-source\spring-fra mework-4.2.x-e\spring-framework-4.2.x\ > 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. 請按任意鍵繼續. . . ----------------------------------------------------------------------- STEP 3: generate root project Eclipse metadata Unfortunately, Eclipse does not allow for importing project hierarchies, so we had to skip root project metadata generation in the during step 1. In this step we simply generate root project metadata so you can import it in the next step. The command run will be: gradlew :eclipse Press the enter key when ready. 請按任意鍵繼續. . . :buildSrc:compileJava UP-TO-DATE :buildSrc:compileGroovy UP-TO-DATE :buildSrc:processResources UP-TO-DATE :buildSrc:classes UP-TO-DATE :buildSrc:jar UP-TO-DATE :buildSrc:assemble UP-TO-DATE :buildSrc:compileTestJava UP-TO-DATE :buildSrc:compileTestGroovy UP-TO-DATE :buildSrc:processTestResources UP-TO-DATE :buildSrc:testClasses UP-TO-DATE :buildSrc:test UP-TO-DATE :buildSrc:check UP-TO-DATE :buildSrc:build UP-TO-DATE :eclipseClasspath :eclipseJdtPrepare :eclipseJdt :eclipseProject :eclipseSettings :eclipseWstComponent :eclipse BUILD SUCCESSFUL Total time: 53.201 secs ----------------------------------------------------------------------- STEP 4: Import root project into Eclipse/STS Follow the project import steps listed in step 2 above to import the root project. Press enter when complete, and move on to the final step. 請按任意鍵繼續. . . ----------------------------------------------------------------------- STEP 5: Enable Git support for all projects - In the Eclipse/STS Package Explorer, select all spring* projects. - Right-click to open the context menu and select Team > Share Project... - In the Share Project dialog that appears, select Git and press Next - Check "Use or create repository in parent folder of project" - Click Finish When complete, you'll have Git support enabled for all projects. You're ready to code! Goodbye!