栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

Spring 源码编译

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Spring 源码编译

一、环境准备

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

1、maven

2、jdk1.8

3、Idea2020.3.1x64

二、源码下载
    1. 进入https://github.com/spring-projects/spring-framework

    2. 下载

      本次作者下载得版本是最新版本V5.3.8

三、Gradle下载

可以自己下载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();
    }
}

最后运行

 

运行成功,完成编译

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/337713.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号