天天看點

intellij idea15搭建spring源碼閱讀環境intellij idea15搭建spring源碼閱讀環境

标簽: 源碼學習

(1)下載下傳intellij idea15

建議下載下傳ultimate版本,這樣對web開發的支援元件比較多,開發較為友善,有經濟能力的建議支援正版,沒有的話你懂的。

(2)下載下傳jdk8,配置java環境

(3)clone spring源碼

下載下傳源碼後别着急用idea打開,首先閱讀源碼中的import-into-idea.md檔案,檔案内容如下,按着一步步操作即可

within your locally cloned spring-framework working directory:

1. pre-compile <code>spring-oxm</code> with <code>./gradlew cleanidea :spring-oxm:compiletestjava</code>

2. import into idea (file-&gt;import project-&gt;import from external model-&gt;gradle)

3. set the project jdk as appropriate (1.8+)

4. exclude the <code>spring-aspects</code> module (go to file-&gt;project structure-&gt;modules)

5. code away

<code>spring-oxm</code> should be pre-compiled since it’s using repackaged dependencies (see *repackjar tasks)

<code>spring-aspects</code> does not compile out of the box due to references to aspect types unknown to idea.

should be excluded from the overall project to avoid compilation errors.

while all junit tests pass from the command line with gradle, many will fail when run from idea.

resolving this is a work in progress. if attempting to run all junit tests from within idea, you will

likely need to set the following vm options to avoid out of memory errors:

-xx:maxpermsize=2048m -xmx2048m -xx:maxheapsize=2048m

(4)用idea打開spring源碼 随便寫了一個test,運作結果如下圖所示:

intellij idea15搭建spring源碼閱讀環境intellij idea15搭建spring源碼閱讀環境

問題:

(1)源碼按照上面導入後,gradle build 也成功了,但是自己寫測試代碼可能還會報一些包找不到的問題,如圖

intellij idea15搭建spring源碼閱讀環境intellij idea15搭建spring源碼閱讀環境

這是由于idea打開spring源碼後依賴沒有正确配置,添加依賴即可解決

intellij idea15搭建spring源碼閱讀環境intellij idea15搭建spring源碼閱讀環境

(2)如果依賴都正确配置了,但是程式還是無法運作,那可能是依賴順序問題,詳細可查閱這個部落格

<a href="http://www.wurenny.com/2015/04/17/186">http://www.wurenny.com/2015/04/17/186</a>