一,环境配置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源码深刻研究之路。
本文版权全部,转载请注明出处