此次作者编译得环境如下:
1、maven
2、jdk1.8
3、Idea2020.3.1x64
二、源码下载-
-
进入https://github.com/spring-projects/spring-framework
-
下载
本次作者下载得版本是最新版本V5.3.8
-
可以自己下载Gradle,也可以由IDEA自己下载,如自己下载,可以去spring-framework-maingradlewrappergradle-wrapper.properties文件中,根据下图所示得地址进行下载
四、修改镜像
进入到build.gradle文件下,设置镜像,找到如下图所示得位置
并添加下列信息
repositories {
maven{ url 'https://maven.aliyun.com/nexus/content/groups/public/'}
maven{ url 'https://maven.aliyun.com/nexus/content/repositories/jcenter'}
mavenCentral()
maven { url "https://repo.spring.io/libs-spring-framework-build" }
}
五、编译
安装官网的方式进行编译,打开源码文件夹,在cmd命令中进行输入
gradlew :spring-oxm:compileTestJava
配置了镜像之后,编译速度会很快
六、导入项目到Idea中
导入到Idea后会需要等待一点时间等待编译完成
七、添加测试模块
新建moudle.gradle在新建的moudle下的添加依赖
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
compile(project(":spring-context"))
}
compile(project(":spring-context")) 代表本项目的spring-context,因为要用到注解。
八、新建测试类如上图所示,新建两个测试类进行测试
1、新建一个bean类
package com.beans;
import org.springframework.stereotype.Service;
@Service
public class Testt {
public void sayHello(){
System.out.println("Hello World!");
}
}
2、添加启动配置类
package com.beans;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
@Configuration
@ComponentScan("com.beans")
public class mainT {
public static void main(String[] args) {
ApplicationContext context = new AnnotationConfigApplicationContext(mainT.class);
Testt bean = context.getBean(Testt.class);
bean.sayHello();
}
}
最后运行
运行成功,完成编译



