到github 下載一份源代碼html
https://github.com/spring-projects/spring-frameworkjava
我這裏放在 D:\gitclone\spring-framework 目錄git
構建項目前須要下載gradle,到http://gradle.org/下載,而後配置GRADLE_HOME和path路徑github
進入spring目錄, 執行命令: gradle eclipse -x :eclipseweb
第一次執行會花比較長的時間,gradle會去下載許多依賴庫, spring
也能夠在子項目裏單獨構建的命令:websocket
D:\gitclone\spring-framework>gradle eclipse -x :eclipse網絡
這個過程會比較漫長,有效子項目也可能由於網絡問題而中斷eclipse
能夠進入到子項目路徑下 執行 gradle cleanidea eclipse,來單獨構建項目socket
好比D:\gitclone\spring-framework\spring-websocket>gradle cleanidea eclipse
構建過程碰到的問題
一、spring-core項目裏丟失了兩個jar 包
spring-objenesis-repack-2.4.jar 和spring-cglib-repack-3.2.3.jar
在bulid.gradle 文件裏在找到了兩個 task cglibRepackJar和objenesisRepackJar
http://www.blogjava.net/wldandan/archive/2012/06/27/381605.html
C:\Users\Administrator>D: |
構建後就好了
二、我發現spring-oxm 項目也丟失了jaxb和xmlbeans jar 包,
我在 spring-oxm 子項目裏執行
D:\gitclone\spring-framework\spring-oxm>gradle compileTestJava
構建後就能夠
四、子項目spring-beans-groovy提示GroovyDynamicElementReader這個類不存在
緣由是須要安裝一個eclipse的groovy插件。
在eclipse的 Help -> Install New Software 中,添加groovy的下載鏈接:
http://dist.springsource.org/release/GRECLIPSE/e4.3/
而後全選後,開始下載,下載完後,重啓eclipse,而後clean一下項目就搞定了。
解決了全部錯誤後,獲得咱們想要的源碼項目,以下圖,代碼整整齊齊,沒有報錯很清爽
在官方網站裏獲取到 入門實例
http://projects.spring.io/spring-framework/
package hello; public interface MessageService { String getMessage(); } |
package hello; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @Component public class MessagePrinter { final private MessageService service; @Autowired public MessagePrinter(MessageService service) { this.service = service; } public void printMessage() { System.out.println(this.service.getMessage()); } } |
package hello; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.*; @Configuration @ComponentScan public class Application { @Bean MessageService mockMessageService() { return new MessageService() { public String getMessage() { return "Hello World!"; } }; } public static void main(String[] args) { ApplicationContext context = new AnnotationConfigApplicationContext(Application.class); MessagePrinter printer = context.getBean(MessagePrinter.class); printer.printMessage(); } } |
運行後親測無誤。接下來就能夠開始spring 的源碼閱讀旅程了。