spring5.1源碼環境搭建
根據子路老師的視頻教程整理spring5.1的安裝步驟。
1:使用gitbash在碼雲上下載springframework的地址https://gitee.com/mirrors/Spring-Framework.git
2:根據下載下來的源碼,查看ReadMe.md,打開Build from Source 的鏈接地址
https://github.com/spring-projects/spring-framework/wiki/Build-from-Source
3:使用gitbash在Spring-Framework目錄下執行命令
3.1: ./gradlew build
3.2: ./gradlew :spring-oxm:compileTestJava
4:將源碼導入idea,配置gradle如下:
5:在springframework下新建模塊spring-chunyang:
5.1 在build.gradle下修改配置增加spring-context如下:
dependencies { compile(project(":spring-context")) testCompile group: 'junit', name: 'junit', version: '4.12' } 5.2 接著進行測試打擊效果: 5.2.1新建類名如下
5.2.2代碼如下:
package com.shadow.app; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; @Configuration @ComponentScan("com.shadow") public class AppConfig { }
package com.shadow.app; import org.springframework.stereotype.Component; @Component public class A { }
package com.shadow.app; import org.springframework.context.annotation.AnnotationConfigApplicationContext; public class Test { public static void main(String[] args) { AnnotationConfigApplicationContext ac =new AnnotationConfigApplicationContext(AppConfig.class); System.out.println(ac.getBean(A.class)); } } 5.3運行Test類的main方法打印出類的引用信息 6:由於使用gradle編譯代碼,每次執行代碼都需要加載相關模塊,運行比較緩慢。由此可以更改為idea運行模式。在idea下的setting的gradle下修改為idea. 6.1在idea執行rebuild project.會在源碼的每個模塊下生成out輸出目錄,同時把gradle編譯的build目錄刪除了 6.2 執行Test類,發現運行會快很多了。 至此源碼環境搭建完成。