SpringFramework源码分析(一)——源码下载与编译

准备工作

确认本地有无spring要求的jdk版本

springframework使用高版本的jdk编译,可以查看spring要求的jdk版本

Build from Source https://github.com/spring-projects/spring-framework/wiki/Build-from-Source

下载spring的源码

git clone git@github.com:spring-projects/spring-framework.git
cd spring-framework

编译源码

使用命令行编译
./gradlew build
推荐使用IDEA编译,可以针对多java环境配置工程

打开IDEA->Gradle->spring->Tasks->build->build

spring
|--Tasks
	|--build
		|--assemble
		|--build

构建成功

BUILD SUCCESSFUL in xxxxms

编译过程中遇到的问题处理

gradle未配置代理导致无法下载依赖包
报错日志

Could not determine the dependencies of task ‘:spring-core:cglibRepackJar’.

Could not resolve all files for configuration ‘:spring-core:cglib’.
Could not download cglib-3.3.0.jar (cglib:cglib:3.3.0)
> Could not get resource ‘https://repo.maven.apache.org/maven2/cglib/cglib/3.3.0/cglib
-3.3.0.jar’.
> Could not GET ‘https://repo.maven.apache.org/maven2/cglib/cglib/3.3.0/cglib-3.3.0
.jar’.
> The server may not support the client’s requested TLS protocol versions: (TLSv
1.2). You may need to configure the client to allow other protocols to be used. See: https:/
/docs.gradle.org/6.8.3/userguide/build_environment.html#gradle_system_properties
> sun.security.validator.ValidatorException: PKIX path building failed: sun.s
ecurity.provider.certpath.SunCertPathBuilderException: unable to find valid certification pa
th to requested target

Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to ge
t more log output. Run with --scan to get full insights.

解决方法

在项目的gradle.properties中配置代理

# 代理服务器ip或域名
systemProp.http.proxyHost=proxy.xxx.com
# 代理端口
systemProp.http.proxyPort=443
# 代理权限用户名
systemProp.http.proxyUser=user
# 代理权限密码
systemProp.http.proxyPassword=password
# 不需要代理地址,多个以|分割
systemProp.http.nonProxyHosts=localhost|xxx
程序包jdk.jfr不存在import jdk.jfr.Category
报错日志

spring-core\src\main\java\org\springframework\core
metrics\jfr\FlightRecorderStartupEvent.java:19: 错误: 程序包jdk.jfr不存在
import jdk.jfr.Category;
^
spring-core\src\main\java\org\springframework\core
metrics\jfr\FlightRecorderStartupEvent.java:20: 错误: 程序包jdk.jfr不存在
import jdk.jfr.Description;
^
spring-core\src\main\java\org\springframework\core
metrics\jfr\FlightRecorderStartupEvent.java:21: 错误: 程序包jdk.jfr不存在
import jdk.jfr.Event;
^
spring-core\src\main\java\org\springframework\core
metrics\jfr\FlightRecorderStartupEvent.java:22: 错误: 程序包jdk.jfr不存在
import jdk.jfr.Label;
^
spring-core\src\main\java\org\springframework\core
metrics\jfr\FlightRecorderStartupEvent.java:37: 错误: 找不到符号

解决方法

由于gradle jvm还是采用jdk1.8等低版本导致的,需要修改为高版本jdk

如果使用IDEA直接编译,可以在IDEA中配置。打开settings->Build Tools->Gradle或者直接在settings中搜索Gradle编辑Gradle projects的Gradle JVM选择高版本jdk,然后点击Apply。

没有安装证书或不允许低版本TLS协议
报错日志

Execution failed for task ‘:spring-tx:compileKotlin’.

Could not resolve all files for configuration ‘:spring-tx:optional’.
Could not resolve com.ibm.websphere:uow:6.0.2.17.
Required by:
project :spring-tx
> Could not resolve com.ibm.websphere:uow:6.0.2.17.
> Could not get resource ‘https://repo.spring.io/libs-spring-framework-build/com/ibm/websphere/uow/6.0.2.17/uow-6.0.2.17.pom’.
> Could not GET ‘https://repo.spring.io/libs-spring-framework-build/com/ibm/websphere/uow/6.0.2.17/uow-6.0.2.17.pom’.
> The server may not support the client’s requested TLS protocol versions: (TLSv1, TLSv1.1, TLSv1.2). You may need to configure the client to allow other protocols to be used. See: https://docs.gradle.org/6.8.3/userguide/build_environment.html#gradle_system_properties
> PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
> Could not resolve com.ibm.websphere:uow:6.0.2.17.
> Could not get resource ‘https://repo.maven.apache.org/maven2/com/ibm/websphere/uow/6.0.2.17/uow-6.0.2.17.pom’.
> Could not GET ‘https://repo.maven.apache.org/maven2/com/ibm/websphere/uow/6.0.2.17/uow-6.0.2.17.pom’.
> The server may not support the client’s requested TLS protocol versions: (TLSv1, TLSv1.1, TLSv1.2). You may need to configure the client to allow other protocols to be used. See: https://docs.gradle.org/6.8.3/userguide/build_environment.html#gradle_system_properties
> PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

解决方法

在jre/lib/security目录下安装公司证书,并替换公司的仓库地址

修改仓库地址,可以替换为阿里云源

repositories {
    mavenCentral()
//    maven { url "https://repo.spring.io/libs-spring-framework-build" }
	maven { url "https://maven.aliyun.com/repository/public" }
	maven { url "https://maven.aliyun.com/repository/spring" }
}
```## 准备工作

### 确认本地有无spring要求的jdk版本

springframework使用高版本的jdk编译,可以查看spring要求的jdk版本

[Build from Source https://github.com/spring-projects/spring-framework/wiki/Build-from-Source](https://github.com/spring-projects/spring-framework/wiki/Build-from-Source)。

### 下载spring的源码

```shell
git clone git@github.com:spring-projects/spring-framework.git
cd spring-framework

编译源码

使用命令行编译
./gradlew build
推荐使用IDEA编译,可以针对多java环境配置工程

打开IDEA->Gradle->spring->Tasks->build->build

spring
|--Tasks
	|--build
		|--assemble
		|--build

构建成功

BUILD SUCCESSFUL in xxxxms

编译过程中遇到的问题处理

gradle未配置代理导致无法下载依赖包
报错日志

Could not determine the dependencies of task ‘:spring-core:cglibRepackJar’.

Could not resolve all files for configuration ‘:spring-core:cglib’.
Could not download cglib-3.3.0.jar (cglib:cglib:3.3.0)
> Could not get resource ‘https://repo.maven.apache.org/maven2/cglib/cglib/3.3.0/cglib
-3.3.0.jar’.
> Could not GET ‘https://repo.maven.apache.org/maven2/cglib/cglib/3.3.0/cglib-3.3.0
.jar’.
> The server may not support the client’s requested TLS protocol versions: (TLSv
1.2). You may need to configure the client to allow other protocols to be used. See: https:/
/docs.gradle.org/6.8.3/userguide/build_environment.html#gradle_system_properties
> sun.security.validator.ValidatorException: PKIX path building failed: sun.s
ecurity.provider.certpath.SunCertPathBuilderException: unable to find valid certification pa
th to requested target

Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to ge
t more log output. Run with --scan to get full insights.

解决方法

在项目的gradle.properties中配置代理

# 代理服务器ip或域名
systemProp.http.proxyHost=proxy.xxx.com
# 代理端口
systemProp.http.proxyPort=443
# 代理权限用户名
systemProp.http.proxyUser=user
# 代理权限密码
systemProp.http.proxyPassword=password
# 不需要代理地址,多个以|分割
systemProp.http.nonProxyHosts=localhost|xxx
程序包jdk.jfr不存在import jdk.jfr.Category
报错日志

spring-core\src\main\java\org\springframework\core
metrics\jfr\FlightRecorderStartupEvent.java:19: 错误: 程序包jdk.jfr不存在
import jdk.jfr.Category;
^
spring-core\src\main\java\org\springframework\core
metrics\jfr\FlightRecorderStartupEvent.java:20: 错误: 程序包jdk.jfr不存在
import jdk.jfr.Description;
^
spring-core\src\main\java\org\springframework\core
metrics\jfr\FlightRecorderStartupEvent.java:21: 错误: 程序包jdk.jfr不存在
import jdk.jfr.Event;
^
spring-core\src\main\java\org\springframework\core
metrics\jfr\FlightRecorderStartupEvent.java:22: 错误: 程序包jdk.jfr不存在
import jdk.jfr.Label;
^
spring-core\src\main\java\org\springframework\core
metrics\jfr\FlightRecorderStartupEvent.java:37: 错误: 找不到符号

解决方法

由于gradle jvm还是采用jdk1.8等低版本导致的,需要修改为高版本jdk

如果使用IDEA直接编译,可以在IDEA中配置。打开settings->Build Tools->Gradle或者直接在settings中搜索Gradle编辑Gradle projects的Gradle JVM选择高版本jdk,然后点击Apply。

没有安装证书或不允许低版本TLS协议
报错日志

Execution failed for task ‘:spring-tx:compileKotlin’.

Could not resolve all files for configuration ‘:spring-tx:optional’.
Could not resolve com.ibm.websphere:uow:6.0.2.17.
Required by:
project :spring-tx
> Could not resolve com.ibm.websphere:uow:6.0.2.17.
> Could not get resource ‘https://repo.spring.io/libs-spring-framework-build/com/ibm/websphere/uow/6.0.2.17/uow-6.0.2.17.pom’.
> Could not GET ‘https://repo.spring.io/libs-spring-framework-build/com/ibm/websphere/uow/6.0.2.17/uow-6.0.2.17.pom’.
> The server may not support the client’s requested TLS protocol versions: (TLSv1, TLSv1.1, TLSv1.2). You may need to configure the client to allow other protocols to be used. See: https://docs.gradle.org/6.8.3/userguide/build_environment.html#gradle_system_properties
> PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
> Could not resolve com.ibm.websphere:uow:6.0.2.17.
> Could not get resource ‘https://repo.maven.apache.org/maven2/com/ibm/websphere/uow/6.0.2.17/uow-6.0.2.17.pom’.
> Could not GET ‘https://repo.maven.apache.org/maven2/com/ibm/websphere/uow/6.0.2.17/uow-6.0.2.17.pom’.
> The server may not support the client’s requested TLS protocol versions: (TLSv1, TLSv1.1, TLSv1.2). You may need to configure the client to allow other protocols to be used. See: https://docs.gradle.org/6.8.3/userguide/build_environment.html#gradle_system_properties
> PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

解决方法

在jre/lib/security目录下安装公司证书,并替换公司的仓库地址

修改仓库地址,可以替换为阿里云源

repositories {
    mavenCentral()
//    maven { url "https://repo.spring.io/libs-spring-framework-build" }
	maven { url "https://maven.aliyun.com/repository/public" }
	maven { url "https://maven.aliyun.com/repository/spring" }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值