Idea构建、编译Spring源码
-
软件准备
-
JDK版本:1.8.0_231
https://download.csdn.net/download/Keiissland/11990344
-
Gradle版本:gradle-4.9
https://downloads.gradle-dn.com/distributions/gradle-4.9-bin.zip
-
Spring版本:spring-framework-5.0
https://github.com/spring-projects/spring-framework/tree/5.0.x
-
idea版本:ideaIU-2019.2.3
http://www.jetbrains.com/idea/download/#section=windows
-
-
环境准备
-
JDK安装及配置(略)
-
Gradle安装、配置、集成idea
-
参考地址:
https://blog.csdn.net/weixin_42717959/article/details/84858021
-
-
-
项目检出
-
采用Git地址clone的方式(https://github.com/spring-projects/spring-framework.git)
-
导入项目
-
等待Jar包的下载
-
配置一下Gradle(File --> Settings --> Gradle)
-
-
编译项目
-
使用Gradle中的compileTestJava,用于跑项目中的单元测试(会连带编译项目),期间控制台出现乱码不必理会
-
编译结束
-
-
编写测试工程(spring-helloword)
-
在总工程下,新建一个Module
-
项目类型为Gradle
-
设置项目名为spring-helloworld
-
设置路径
-
项目新建完毕(左面的项目文件都会展开)
-
在新建的spring-helloword项目中,导入spring-context依赖
-
编写测试代码
-
具体代码
/** * Config.java */ @ComponentScan("com.keiissland.helloworld") public class Config { }
/** * HelloService.java */ @Service public class HelloService { public void sayHello() { System.out.println("Hello World! "); } }
/** * Application.java */ public class Application { public static void main(String[] args) { AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Config.class); HelloService helloService = (HelloService) context.getBean("helloService"); helloService.sayHello(); } }
-
-
运行测试工程代码出现的错误
-
错误一
Error:(354, 51) java: 找不到符号 符号: 变量 CoroutinesUtils 位置: 类 org.springframework.core.ReactiveAdapterRegistry.CoroutinesRegistrar
解决方式
https://blog.csdn.net/ULiYJ/article/details/95760122
-
错误二
Error:(26, 38) java: 找不到符号 符号: 类 InstrumentationSavingAgent 位置: 程序包 org.springframework.instrument
解决方式
-