一,環(huán)境配置
操作系統(tǒng):Unbutu14.04LTS
JDK: 1.8.0_40
git: 1.9.1
gradle: 2.2.1
二,源碼下載-編譯-導(dǎo)入eclipse-驗(yàn)證
1,下載
使用git直接clone Spring源碼到本地:git clone git://github.com/SpringSource/spring-framework.git
2,編譯
編譯過程,這里所謂的編譯是通過gradle工具編譯Spring-framework的項(xiàng)目文件,主要干的事情就是下載Spring各個(gè)模塊依賴的jar包,這個(gè)過程一般情況下非常慢,可能是因?yàn)橘Y源都在墻外,并且可能出現(xiàn)jar包很久下載不下來的情況,這時(shí)候直接ctrl+c退出編譯命令后再次執(zhí)行命令,對(duì)于已經(jīng)下載下來的以來包不會(huì)再次下載,所以編譯的過程相當(dāng)與可以斷線重連的效果。
①進(jìn)入源碼目錄執(zhí)行:gradle eclipse -x :eclipse (我整整花費(fèi)了1上午才編譯通過)
②,執(zhí)行g(shù)radle install 這個(gè)具體神馬作用我還不清楚,但是不執(zhí)行這個(gè)命令導(dǎo)入①編譯后的代碼進(jìn)eclipse后會(huì)有一堆build path error,猜想應(yīng)該是將步驟1中down下來的依賴存入gradle本地倉庫以便于項(xiàng)目查找使用相關(guān)依賴。
③,直接通過eclipse的import到入Spring-framework源碼目錄
groovy這個(gè)項(xiàng)目可能會(huì)有方法找不到,主要原因時(shí)你的eclipse沒有裝Groovy插件,裝上后clean下項(xiàng)目就OK了
④,驗(yàn)證
寫一個(gè)簡單的測(cè)試項(xiàng)目,簡單的IoC調(diào)用功能,依賴spring-context項(xiàng)目

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 args10 */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.xsd10 ">11 12 <bean id="lover" class="com.test.bean.Lover" scope="prototype"></bean>13 14 </beans>
三,總結(jié)
本文主要小結(jié)了Spring源碼的下載(github),編譯(gradle),導(dǎo)入eclipse的過程,最后簡單測(cè)試了導(dǎo)入eclipse后的SpringIoC模塊的功能。從此開啟了Spring源碼深入研究之路。
本文版權(quán)所有,轉(zhuǎn)載請(qǐng)注明出處
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注