首页 > 编程语言 >Spring源码环境搭建

Spring源码环境搭建

时间:2023-02-06 23:45:22浏览次数:56  
标签:git name spring gradle 源码 Spring public 搭建

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

image-20220605100511006-16544058028731

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()
  }
}

image-20220605101341219-16544058028732

整合IDEA

指定仓库

image-20220605101735219-16544058028733

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

image-20220605101832297-16544058028734

image-20220606001035945

配置本地gradle

image-20220605102034211-16544058028735

新建Module测试

新建Module -> gradle

image-20220605102339707-16544058028746

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);
   }
}

image-20220605102740988-16544058028747

关联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

image-20220605104345558-16544058028748

image-20220605104542010-16544058028749

补充: 针对下载的压缩包重新关联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 .

image-20220607064748976

同样的IDEA设置修改

Ignore files and folders

把target删掉

image-20220607065805062

IDEA报错

更新报错

git branch --set-upstream-to=origin/main main

image-20220605105652640-165440580287410

支持中文

-Dfile.encoding=UTF-8

重启生效

image-20220605111242309-165440580287411

标签:git,name,spring,gradle,源码,Spring,public,搭建
From: https://www.cnblogs.com/iniwu/p/17097047.html

相关文章