到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 的源码阅读旅程了。