Spring源码环境搭建

使用Gitee从GitHub导入Spring源码到自己仓库

Spring在github的仓库地址:https://github.com/spring-projects/spring-framework
在这里插入图片描述

使用Idea导入项目

导入Spring项目

在这里插入图片描述

配置gradle

在这里插入图片描述

下载高版本的JDK及在gradle中的配置方式

http://www.codebaoku.com/jdk/jdk-index.html

注意:
后续报运行测试环境搭建是否成功,报 错误: 无效的源发行版:17
所以这里是下载JDK17版本
后续的jdk15的版本操作都用jdk17代替
在这里插入图片描述
直接下载压缩包,解压缩
在这里插入图片描述
在这里插入图片描述
添加jdk为刚解压的目录

等待下载相关jar包

在这里插入图片描述

下载失败的情况说明

下载时有时会提示在仓库找不到相关jar,下载失败
这时关闭项目,删除项目中的.idea文件,重新导入项目
在这里插入图片描述
在这里插入图片描述

在这里插入图片描述

环境搭建完成

在这里插入图片描述

测试Spring源码是否搭建成功

测试

新建自己的测试module

在这里插入图片描述
在这里插入图片描述

引入spring-context

参照其他原有工程引入方式
在这里插入图片描述

在my-spring-source-test工程下的build.gradle文件

dependencies {
    //引入Spring核心容器
    api(project(":spring-context"))
    testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.0'
    testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.0'
}

选中自己的测试module刷新
在这里插入图片描述

引入其他jar依赖

引入lombok
https://mvnrepository.com/artifact/org.projectlombok/lombok/1.18.20
在这里插入图片描述

my-spring-source-test下build.gradle配置

dependencies {
    //引入Spring核心容器
    api(project(":spring-context"))
    testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.0'
    testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.0'
    // https://mvnrepository.com/artifact/org.projectlombok/lombok
    compileOnly group: 'org.projectlombok', name: 'lombok', version: '1.18.20'

}

使用
在这里插入图片描述

代码测试

在这里插入图片描述
beans.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	   xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
	<bean class="com.myspring.sourcetest.bean.Person" id="person"></bean>
</beans>

运行
在这里插入图片描述

报错说明

No candidates found for method call api. 引入依赖报错

没有pai方法

解决:
https://docs.gradle.org/current/userguide/java_library_plugin.html#sec:java_library_separation

将build.gradle配置

plugins {
    id 'java'
}

改为

plugins {
    id 'java-library'
}

仓库地址修改为https

在这里插入图片描述
在这里插入图片描述
选中自己的测试module刷新
在这里插入图片描述

找不到相应jar包问题

阿里云仓库找不到

在这里插入图片描述
https://docs.gradle.org/current/userguide/declaring_repositories.html

移除D:\File\development_data\gradle\gradle-7.4.2\init.d下的init.gradle下载加速配置

在这里插入图片描述
选中自己的测试module刷新
在这里插入图片描述

maven仓库无法下载

引入lombok时报错
上面已经将阿里仓库配置移除了,所以从maven仓库拉取
在这里插入图片描述

解决:
在本module的build.gradle配置

repositories {
//    mavenCentral()
    maven {
        url "https://maven.aliyun.com/repository/public"
    }
}

选中自己的测试module刷新
在这里插入图片描述

综合仓库配置方案

目前情况
根据最初的init.gradle文件配置
在这里插入图片描述
有相关jar包找不到

Could not find netty-codec-http2-4.1.77.Final.jar (io.netty:netty-codec-http2:4.1.77.Final).
Searched in the following locations:
    https://maven.aliyun.com/repository/jcenter/io/netty/netty-codec-http2/4.1.77.Final/netty-codec-http2-4.1.77.Final.jar

Possible solution:
 - Declare repository providing the artifact, see the documentation at https://docs.gradle.org/current/userguide/declaring_repositories.html

在init.d下排除init.gradle配置后,从maven仓库拉取(速度慢,报无法下载)

所以在moudule的build.gradle中单独配置仓库地址

repositories {
//    mavenCentral()
    maven {
        url "https://maven.aliyun.com/repository/public"
    }
}

存在问题:
在导入其他项目源码时,由于在init.d下排除了init.gradle配置,会走maven仓库下载

尝试的解决方案:
修改init.gradle配置
在这里插入图片描述
在这里插入图片描述
项目工程重新加载
在这里插入图片描述
提示警告
此版本中使用了不推荐的Gradle功能,使其与Gradle 8.0不兼容。

Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.

You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.

See https://docs.gradle.org/7.4.2/userguide/command_line_interface.html#sec:command_line_warnings

BUILD SUCCESSFUL in 4m 40s
7 actionable tasks: 7 up-to-date

A build scan was not published as you have not authenticated with server 'ge.spring.io'.

Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.

You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.

See https://docs.gradle.org/7.4.2/userguide/command_line_interface.html#sec:command_line_warnings

BUILD SUCCESSFUL in 1s

错误: 无效的源发行版:17

运行测试时报错
使用jdk17版本
设置
File-Settings
1
在这里插入图片描述
2
在这里插入图片描述
File-Project Structure
报错:

错误: 加载主类 com.myspring.sourcetest.BeanTest 时出现 LinkageError
	java.lang.UnsupportedClassVersionError: com/myspring/sourcetest/BeanTest has been compiled by a more recent version of the Java Runtime (class file version 61.0), this version of the Java Runtime only recognizes class file versions up to 59.0

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':my-spring-source-test:BeanTest.main()'.
> Process 'command 'D:/File/development_data/jdk/jdk-15.0.2/bin/java.exe'' finished with non-zero exit value 1

1
在这里插入图片描述
2
在这里插入图片描述

  • 3
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Thinking in Coder

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值