0
点赞
收藏
分享

微信扫一扫

Spring源码编译

在觉 2022-01-08 阅读 123

目录

环境准备

1、jdk1.8

2、git

3、gradle

 4、代码获取

编译准备

1、修改配置

 2、预编译

 3、IDEA 配置及编译

验证测试

1、新建module

 2、修改配置

 3、代码测试


环境准备

1、jdk1.8

       

2、git

3、gradle

下载地址:

Gradle Distributions

选择一个版本

下载并解压到自己喜欢的目录,如下

配置环境变量

GRADLE_HOME、GRADLE_USER_HOME、PATH

 gradle仓库源配置(可不配置)

在Gradle安装目录下的 init.d 文件夹下,新建一个 init.gradle 文件,里面填写以下配置。

D:\pace\gradle-5.4.1\init.d

allprojects {
    repositories {
        maven { url 'file:///D:/gradle_repository'}
        mavenLocal()
        maven { name "Alibaba" ; url "https://maven.aliyun.com/repository/public" }
        maven { name "Bstek" ; url "http://nexus.bsdn.org/content/groups/public/" }
        mavenCentral()
    }

    buildscript { 
        repositories { 
            maven { name "Alibaba" ; url 'https://maven.aliyun.com/repository/public' }
            maven { name "Bstek" ; url 'http://nexus.bsdn.org/content/groups/public/' }
            maven { name "M2" ; url 'https://plugins.gradle.org/m2/' }
        }
    }
}

 4、代码获取

打开GitHub 搜索 spring-framework 或者直接点开  GitHub - spring-projects/spring-framework: Spring Framework

或者在gitee 上获取  搜索 spring-framework 或点击下面的网址

Spring-Framework: Spring Framework 是一个开源的Java/Java EE全功能栈(full-stack)的应用程序框架,以Apache许可证形式发布,也有.NET平台上的移植版本

以gitee为例:

1、克隆spring源码到本地

2、切换分支 

编译准备

1、修改配置

在编译过程中,Spring会去自动下载一些依赖的包,默认使用的是官方的镜像,下载比较慢,修改配置从国内镜像下载

将下面的配置 写入配置文件对应的位置:

maven { url "http://maven.aliyun.com/nexus/content/groups/public" }

 

注释掉 build.gradle 中影响编译的部分

 2、预编译

  进入spring源码位置,打开命令窗口,执行  gradlew :spring-oxm:compileTestJava

 3、IDEA 配置及编译

 idea 版本:IntelliJ IDEA 2020.2.3 x64

 导入代码

编译成功

验证测试

1、新建module

 2、修改配置

在build.gradle中 添加  

compile(project(":spring-context")) 

 3、代码测试

package com.liangguang.testSpring;

/**
 * @Author: LiangGuang
 * @Date: 2022/1/8 0:52
 * @Description:
 */
public class Person {
	private String name;

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
}

package com.liangguang.testSpring;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * @Author: LiangGuang
 * @Date: 2022/1/8 0:52
 * @Description:
 */
public class MainTest {
	public static void main(String[] args) {
		ApplicationContext ac = new ClassPathXmlApplicationContext("beans.xml");
		Person bean = ac.getBean(Person.class);
		System.out.println(bean.getName());
	}
}

配置文件 

<?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 id="person" class="com.liangguang.testSpring.Person">
		<property name="name" value="liangguang"></property>
	</bean>
</beans>

运行结果

举报

相关推荐

0 条评论