一、编译前的准备
介绍下环境
jdk使用 jdk-11.0.5
idea使用2019.2.4版本
gradle使用 gradle-5.6.3
说明idea2019.3有bug,会造成源码构建失败
1、下载gradle配置环境变量
gradle下载地址 gradle官网(https://gradle.org/releases/)
在系统高级配置里配置环境变量
我的gradle解压到了
2、下载spring源码
访问GitHub地址https://github.com/spring-projects/spring-framework
解压spring源码
打开
针对build.gradle文件第3行,150行 配置国内镜像加速,
仓库名称 | 代理源地址 | 使用地址 |
---|---|---|
central | https://repo1.maven.org/maven2/ | https://maven.aliyun.com/repository/central 或 https://maven.aliyun.com/nexus/content/repositories/central |
jcenter | http://jcenter.bintray.com/ | https://maven.aliyun.com/repository/jcenter 或 https://maven.aliyun.com/nexus/content/repositories/jcenter |
public | central仓和jcenter仓的聚合仓 | https://maven.aliyun.com/repository/public 或https://maven.aliyun.com/nexus/content/groups/public |
https://maven.google.com/ | https://maven.aliyun.com/repository/google 或 https://maven.aliyun.com/nexus/content/repositories/google | |
gradle-plugin | https://plugins.gradle.org/m2/ | https://maven.aliyun.com/repository/gradle-plugin 或 https://maven.aliyun.com/nexus/content/repositories/gradle-plugin |
spring | http://repo.spring.io/libs-milestone/ | https://maven.aliyun.com/repository/spring 或 https://maven.aliyun.com/nexus/content/repositories/spring |
spring-plugin | http://repo.spring.io/plugins-release/ | https://maven.aliyun.com/repository/spring-plugin 或 https://maven.aliyun.com/nexus/content/repositories/spring-plugin |
grails-core | https://repo.grails.org/grails/core | https://maven.aliyun.com/repository/grails-core 或 https://maven.aliyun.com/nexus/content/repositories/grails-core |
apache snapshots | https://repository.apache.org/snapshots/ | https://maven.aliyun.com/repository/apache-snapshots 或 https://maven.aliyun.com/nexus/content/repositories/apache-snapshots |
修改后
3行
repositories {
maven { url "https://maven.aliyun.com/repository/spring-plugin" }
maven { url "https://maven.aliyun.com/nexus/content/repositories/spring-plugin" }
maven { url "https://repo.spring.io/plugins-release" }
}
150行处
repositories {
maven { url "https://maven.aliyun.com/repository/central" }
maven { url "https://repo.spring.io/libs-release" }
mavenLocal()
}
二、导入源码
打开导入源码
导入之后开始编译,我第一次编译出现如下错误。
修改配置
,重新build
编译成功
编译spring-core
编译成功
编译spring-context
构建成功
三、新建子模块
下一步
下一步,finish
建立成功之后会自动打开各个子模块
在spring-itdog字模块中引入其他依赖
compile(project(":spring-context"))
新建扫描类
package com.hzau;
import org.springframework.context.annotation.ComponentScan;
/**
* @ClassName MyCompentScan
* @Description TODO
* @Author yueyiming
* @Date 2020/1/2 12:15
* @Version 1.0
* https://blog.csdn.net/hzau_itdog
**/
@ComponentScan(basePackages = "com.hzau.**")
public class MyCompentScan {
}
新建实体类
package com.hzau;
import org.springframework.stereotype.Component;
/**
* @ClassName MyBean
* @Description TODO
* @Author yueyiming
* @Date 2020/1/2 12:14
* @Version 1.0
* https://blog.csdn.net/hzau_itdog
**/
@Component
public class MyBean {
public MyBean() {
}
}
进行测试
package com.hzau;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
/**
* @ClassName MyTest
* @Description TODO
* @Author yueyiming
* @Date 2020/1/2 12:14
* @Version 1.0
* https://blog.csdn.net/hzau_itdog
**/
public class MyTest {
public static void main(String[] args) {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(MyCompentScan.class);
MyBean bean = context.getBean(MyBean.class);
System.out.println(bean);
}
}
结果如下: