title: Spring源码环境搭建
date: 2022-06-05 13:07:03
tags: Spring
源码环境搭建
IDEA版本: IDEA-2019.3.5
Gradle: gradle-5.6.4
Spring: 5.2.22.RELEASE
Gradle
版本选择
源码版本: 5.2.22.RELEASE
查看源码gradle版本配置
gradle-5.6.4
gradle版本Releases: https://gradle.org/releases/
gradle-5.6.4下载: https://gradle.org/next-steps/?version=5.6.4&format=all
下载解压
配值系统环境变量
变量名 | 变量值 |
---|---|
GRADLE_HOME | D:\Code\gradle-5.6.4 |
GRADLE_USER_HOME | D:\Code\gradle-5.6.4\gradle-repo |
Path | %GRADLE_HOME%\bin |
配置阿里云加速
https://developer.aliyun.com/mvn/guide
build.gradle
allprojects {
repositories {
maven {
url 'https://maven.aliyun.com/repository/public/'
}
mavenLocal()
mavenCentral()
}
}
整合IDEA
指定仓库
IDEA导入源码
官方github地址: https://github.com/spring-projects/spring-framework
下载源码v5.2.22: https://github.com/spring-projects/spring-framework/releases/tag/v5.2.22.RELEASE
重新设置Gradle
重点: 导入先择Gradle, 点Finish后, Cancel取消下载gradle
配置本地gradle
新建Module测试
新建Module -> gradle
builde.gradle引入spring-context
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
// spring 核心容器
compile(project(":spring-context"))
}
实体类
public class Person {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public String toString() {
return "Person{" +
"name='" + name + '\'' +
'}';
}
}
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.mobini.spring.bean.Person" id="person">
<property name="name" value="mobini"/>
</bean>
</beans>
主方法
public class MainTest {
public static void main(String[] args) throws IOException {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("beans.xml");
Person bean = context.getBean(Person.class);
System.out.println("hello spring");
System.out.println(bean);
}
}
关联GitHub
注意下文补充
git init
git add .
git commit -m "Spring-v5.2.22源码初始化"
git branch -M main
git remote add origin https://github.com/iniwym/spring-framework.git
git push -u origin main
补充: 针对下载的压缩包重新关联GitHub, fork源码请无视
由于spring项目自带
.gitignore
文件spring-framework\spring-aop\src\main\java\org\springframework\aop
目录下的target会被忽略
解决: 分两步 [git add .]
1.先将
.gitignore
文件剪切到其他位置, 执行git add .
2.还原
.gitignore
文件, 再次执行git add .
同样的IDEA设置修改
Ignore files and folders
把target删掉
IDEA报错
更新报错
git branch --set-upstream-to=origin/main main
支持中文
-Dfile.encoding=UTF-8
重启生效
标签:git,name,spring,gradle,源码,Spring,public,搭建 From: https://www.cnblogs.com/iniwu/p/17097047.html