spring 源码解析(二) 2.下载源码,及错误的排除。

这章节是将源码下载下来,自己折腾下。

直接开干!

第一步:复制,git   clone 地址:

GitHub:https://github.com/spring-projects/spring-framework

单击 branches

Clone with HTTPS:https://github.com/spring-projects/spring-framework.git

 

 

第二步:用IDEA  的git  下载。

a图:在欢迎页,使用git 下拉项目。

 

b图:粘贴,clone 链接地址。“Clone”

c图:在下载,耐心等待。

d图:

e图:工程属性设置。

f图:导入后界面展示。

到这里就要暂停下了。需要安装AspectJ。

Spring AOP默认使用AspectJ来实现的,如果想要使用AspectJ特有的功能就需要安装AspectJ。

 

----------------------------start   搭建 AspectJ  环境-------------------------------

AOP大家都不陌生,它是一种编程理念,一种规范,有很多的实现者如Spring AOP,JBoss AOP,还有我们今天要讲的AspectJ。我们平时项目用到最多的是Spring AOP,它是用纯Java实现的,不需要专门的编译过程,不需要特殊的类加载器,它在运行期通过JDK动态代理或者Cglib动态代理的方式向目标类织入增强代码。而AspectJ是语言级的AOP实现,它定义了自己的AOP语法和专门的编译期用来生成符合java字节码规范的class文件。

原文:https://blog.csdn.net/aitangyong/article/details/50770085

AspectJ是Eclipse基金组织的开源项目,它是Java语言的一个AOP实现,是最早、功能比较强大的AOP实现之一,对整套AOP机制都有较好的实现,很多其他语言的AOP实现也借鉴或者采纳了AspectJ中的很多设计。在Java领域,AspectJ中的很多语法结构基本上已经成为AOP领域的标准。

AspectJ框架和Spring框架实现AOP的方式是不一样的,AspectJ是在编译时进行增强,所以它有一个专门的编译器来生成遵守Java字节码编码规范的Class文件。而Spring采用的是动态代理的方式,它并不需要有一个专门的编译器。故也称AspectJ为静态AOP实现,而Spring AOP为动态AOP实现。

官网:https://www.eclipse.org/aspectj/     

下载:https://www.eclipse.org/aspectj/downloads.php

安装:AspectJ 9

AspectJ 1.9.3.RC1, Released 7 Mar 2019

http://www.eclipse.org/downloads/download.php?file=/tools/aspectj/aspectj-1.9.3.RC1.jar

java  -jar  aspectj-1.9.3.jar

  

 

环境变更设置:

 

安装后的文件目录结构:

(1)bin:存放aj、aj5、ajc等命令,其中ajc最常用,是对普通JAVA类进行编译时增强。

(2)docs:存放使用说明、参考手册、API等文档

(3)lib:4个jar是AspectJ的核心类库

(4)相关授权文件

 ----------------------------end   搭建 AspectJ  环境-------------------------------         

直接干。

搭建 IDEA对 Ajc 支持【即使用AspectJ编译器】

此功能,仅 Ultimate 支持。默认情况下 IntelliJ IDEA 使用Javac 编译器。

 

开始,正式,构建。

点单 “构建项目” 按钮 [ ]   build projec

Warning:Kotlin: Classpath entry points to a non-existent location: D:DataCenterIntelljspring-frameworkspring-coreuildlibsspring-objenesis-repack-3.0.1.jar

Warning:Kotlin: Classpath entry points to a non-existent location: D:DataCenterIntelljspring-frameworkspring-coreuildlibsspring-cglib-repack-3.2.10.jar

找到上面问题:

1.选中模块:spring-core模块,按 F4 键   或者  右击》spring-core模块》open module settings

2.了解。

Cglib  官网: 开源GitHub:https://github.com/cglib/cglib

Objenesis  官网:http://objenesis.org/ 

 

3.下载。

在spring-framework目录下执行 :

gradle objenesisRepackJar和gradle cglibRepackJar命令。

会自动在Spring-frameworkspring-coreuildlibs 目录下生成jar包。

 

再次,点单 “构建项目” 按钮 [ ]   build projec

aspectj相关报错:

解决:

选中模块:spring-aop  模块,按 F4 键   或者  右击》spring-core模块》open module settings

Facets 添加 AspectJ  》 spring-aop_main 和 spring-aspects_main

 

再次,点单 “构建项目” 按钮 [ ]   build projec

Information:Builder "ajc" requested rebuild of module chunk "spring-aspects_main"

Information:Kotlin: kotlinc-jvm 1.3.0 (JRE 1.8.0_181-b13)

Information:java: Errors occurred while compiling module 'spring-oxm_test'

Information:javac 1.8.0_181 was used to compile java sources

Information:Modules "spring-oxm_test", "spring-tx_test", "spring-aop_test", "spring-context_test" were fully rebuilt due to project configuration/dependencies changes

Information:2019-05-04 15:48 - Compilation completed with 32 errors and 30 warnings in 1 m 27 s 882 ms

D:DataCenterIntelljspring-frameworkspring-contextsrc estjavaorgspringframeworkvalidationDataBinderTests.java

D:DataCenterIntelljspring-frameworkspring-oxmsrc estjavaorgspringframeworkoxmjaxbJaxb2MarshallerTests.java

D:DataCenterIntelljspring-frameworkspring-oxmsrc estjavaorgspringframeworkoxmjaxbJaxb2UnmarshallerTests.java

问题:单元测试的错误,不影响,如果不喜欢,那就直接删除!

再次点单 “构建项目” 按钮 [ ]   build projec。

应该就不报错。至此报错就排除了。转看下篇。

原文地址:https://www.cnblogs.com/ncepu/p/13694889.html