本文主要是介绍疯狂的橘猫-IDEA编译spring源码记录 - 01 及找不到jdk.jfr.Event,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
疯狂的橘猫-IDEA编译spring源码记录
一,准备工作
项目:spring项目源码
gradle:gradle 6.5以上
IDEA:2019x及以上
JDK:11及以上(之前用1.8编译的踩了一些坑…)
ps:建议gradle6.5x版本以上,下载的时候下载-bin的就可以(all的是带了源码的),搬运地址:
https://blog.csdn.net/qq_43662627/article/details/110942301
以下载的源码地址:
https://gitee.com/lcmgroup/spring-frameworks.git
注:
21年3月最新的Spring源码,但是没注意具体版本,后面翻了以下,应该是5.3.5
二,开始操作
1.打开项目
2.选择
3.勾选设置,注意款框内的都要选择,其他的为默认
点ok过后,gradle会自动构建项目,等…不知道多久…
ps:按照这个来应该是没什么问题的,但是我在执行的时候出了一个问题,解决详情看我的另一个博客:
三,编译spring源码
1.当gradle构建完成后,先编译spring-core。找到core里面的test包,右键点击,选择Run all test编译core.
然后以同样的方法,run spring-context的test包的 Run ‘All Tests’.
四,异常解决:
提示找不到 jdk.jfr.Event
首先jdk版本需要11及其以上,idea版本2019及以上
jfr没有找到的错误提示是更改这里,settings->build.Execution,->compiler->java Compiler->project bytecode version设置11(解决办法在下面的url,的评论中,哈哈哈哈哈)
原文出处:
https://jiannan.blog.csdn.net/article/details/108003744
三,自定义项目
完成自定义项目后,就可以开始进行源码调试了。
1.创建项目
创建完成是这样的
2.引入spring的依赖
修改dependencies 的配置如下:
dependencies {compile project(':spring-core')compile project(':spring-context')testCompile group: 'junit', name: 'junit', version: '4.12'
}
3.完成结构并开始测试
完成项目结构为:
TreeAutoImport
@Configuration
public class TreeAutoImport {@Beanpublic GingkoTree getGingkoTree() {System.out.println("===== lxm.spring.te.config.treeconfig.TreeAutoImport.getGingkoTree 调用 =====");return new GingkoTree();}
}
GingkoTree
public class GingkoTree {private String treeName;private int treeAge;private String address;public void growing(){System.out.println(this);System.out.println("===== 银杏树开始长大 =====");}public String getTreeName() {return treeName;}public void setTreeName(String treeName) {this.treeName = treeName;}public int getTreeAge() {return treeAge;}public void setTreeAge(int treeAge) {this.treeAge = treeAge;}public String getAddress() {return address;}public void setAddress(String address) {this.address = address;}public GingkoTree() {System.out.println("lxm.spring.te.entity.tree.GingkoTree.GingkoTree()的无参构造被调用");}public GingkoTree(String treeName, int treeAge, String address) {this.treeName = treeName;this.treeAge = treeAge;this.address = address;}
}
CatApplication
public class CatApplication {public static void main(String[] args) {//三件套//this//register//refreshAnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(TreeAutoImport.class);GingkoTree gingkoTree = context.getBean(GingkoTree.class);gingkoTree.growing();}
}
4.运行项目
===== lxm.spring.te.config.treeconfig.TreeAutoImport.getGingkoTree 调用 =====
lxm.spring.te.entity.tree.GingkoTree.GingkoTree()的无参构造被调用
lxm.spring.te.entity.tree.GingkoTree@25d250c6
===== 银杏树开始长大 =====Process finished with exit code 0
换电脑了,重新拉代码下来编译了很久通过了,但是在执行 先编译spring-core 的时候提示:
处理方式是升级idea kotlin的插件版本:
升级完成,重启idea然后 编译test就可以通过。
然后又遇到新的问题:
找不到一些包aop的包
比如:
多试了几次重新import就可以了。点击:
这篇关于疯狂的橘猫-IDEA编译spring源码记录 - 01 及找不到jdk.jfr.Event的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!