Spring 源码编译

一、环境准备

此次作者编译得环境如下:

1、maven

2、jdk1.8

3、Idea2020.3.1x64

二、源码下载

三、Gradle下载

可以自己下载Gradle,也可以由IDEA自己下载,如自己下载,可以去spring-framework-main\gradle\wrapper\gradle-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();
    }
}

最后运行

 

运行成功,完成编译

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值