环境准备
gradle安装与idea集成 idea创建gradle项目使用阿里云镜像下载Spring源码并启动运行项目
下载spring源码到idea调整Repositories的本地仓库以及阿里云镜像创建自己的测试module在项目中创建xml,配置bean编写java代码并测试
环境准备由于spring源码使用GRADLE工具构建,所以本地必须要安装好gradle环境
gradle安装与idea集成官网下载即可,配置环境变量与java的配置相同,详情请百度。
官网下载地址:https://gradle.org/releases/
集成到idea中
本地gradle优先使用本地maven仓库配置
注意:**GRADLE_USER_HOME**不能写错。
idea创建gradle项目使用阿里云镜像plugins {
id 'java'
}
group 'org.example'
version '1.0-SNAPSHOT'
repositories {
maven { url "http://maven.aliyun.com/nexus/content/groups/public" }
mavenLocal()
mavenCentral()
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
runtimeonly group: 'org.jetbrains.kotlin', name: 'kotlin-compiler-embeddable', version: '1.3.72'
}
下载Spring源码并启动运行项目
下载spring源码到idea
1.直接在github下载即可,导入到idea过程忽略
github源码地址:https://github.com/spring-projects/spring-framework.git
注意选择所需要调试的版本
5.3.x需要高于JDK8以上的jdk版本,5.2.x支持JDK8及以下的版本
1.记得将bulid.gradle文件名修改成项目名一样的前缀,如:spring-debug.gradle
spring-debug.gradle配置如下
description = "Spring Debug"
group 'org.springframework'
version '6.0.0-SNAPSHOT'
dependencies {
compile(project(":spring-beans"))
compile(project(":spring-core"))
// compile(project(":spring-tx"))
compile(project(":spring-context"))
// implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
}
在项目中创建xml,配置bean
applicationContext.xml内容如下:
编写java代码并测试
package org.clj.test;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class A {
public static void main(String[] args) {
System.out.println("running:===============");
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("ApplicationContext.xml");
A bean = context.getBean(A.class);
System.out.println(bean);
}
}
能够输出bean则说明本地spring项目运行成功



