一,環境配置java
操做系統:Unbutu14.04LTSgit
JDK: 1.8.0_40github
git: 1.9.1spring
gradle: 2.2.1eclipse
二,源碼下載-編譯-導入eclipse-驗證工具
1,下載測試
使用git直接clone Spring源碼到本地:git clone git://github.com/SpringSource/spring-framework.gitgradle
2,編譯ui
編譯過程,這裏所謂的編譯是經過gradle工具編譯Spring-framework的項目文件,主要乾的事情就是下載Spring各個模塊依賴的jar包,這個過程通常狀況下很是慢,多是由於資源都在牆外,而且可能出現jar包好久下載不下來的狀況,這時候直接ctrl+c退出編譯命令後再次執行命令,對於已經下載下來的以來包不會再次下載,因此編譯的過程至關與能夠斷線重連的效果。this
①進入源碼目錄執行:gradle eclipse -x :eclipse (我整整花費了1上午才編譯經過)
②,執行gradle install 這個具體神馬做用我還不清楚,可是不執行這個命令導入①編譯後的代碼進eclipse後會有一堆build path error,猜測應該是將步驟1中down下來的依賴存入gradle本地倉庫以便於項目查找使用相關依賴。
③,直接經過eclipse的import到入Spring-framework源碼目錄
groovy這個項目可能會有方法找不到,主要緣由時你的eclipse沒有裝Groovy插件,裝上後clean下項目就OK了
④,驗證
寫一個簡單的測試項目,簡單的IoC調用功能,依賴spring-context項目
a),TestSpring.java
1 import org.springframework.context.ApplicationContext; 2 import org.springframework.context.support.ClassPathXmlApplicationContext; 3 4 import com.test.bean.Lover; 5 6 7 public class TestSpring { 8 /** 9 * @param args 10 */ 11 @SuppressWarnings("resource") 12 public static void main(String[] args) { 13 ApplicationContext ctx = new ClassPathXmlApplicationContext("bean.xml"); 14 Lover p = ctx.getBean("lover",Lover.class); 15 p.info(); 16 } 17 18 }
b),Lover.java
1 package com.test.bean; 2 3 public class Lover { 4 5 private String name; 6 private int age; 7 8 public String getName() { 9 return name; 10 } 11 public void setName(String name) { 12 this.name = name; 13 } 14 public int getAge() { 15 return age; 16 } 17 public void setAge(int age) { 18 this.age = age; 19 } 20 public void info(){ 21 System.out.println("Spring is a best lover fro you~~~"); 22 } 23 }
c),bean.xml
1 <?xml version="1.0" encoding="UTF-8"?> 2 <beans 3 xmlns="http://www.springframework.org/schema/beans" 4 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 5 xmlns:context="http://www.springframework.org/schema/context" 6 xsi:schemaLocation="http://www.springframework.org/schema/beans 7 http://www.springframework.org/schema/beans/spring-beans-2.5.xsd 8 http://www.springframework.org/schema/context 9 http://www.springframework.org/schema/context/spring-context-2.5.xsd 10 "> 11 12 <bean id="lover" class="com.test.bean.Lover" scope="prototype"></bean> 13 14 </beans>
三,總結
本文主要小結了Spring源碼的下載(github),編譯(gradle),導入eclipse的過程,最後簡單測試了導入eclipse後的SpringIoC模塊的功能。今後開啓了Spring源碼深刻研究之路。
本文版權全部,轉載請註明出處