Spring 源码编译(一)

1、下载源码包

Spring 官网
在这里插入图片描述

下载
在这里插入图片描述

2、修改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" }
		}

3、解压后在当前目录输入cmd

在这里插入图片描述

gradlew :spring-oxm:compileTestJava

只要看到 BUILD SUCCESSFUL 表示编译成功
在这里插入图片描述

4、编译遇到的问题

① 编译过程中遇到下载jar包失败,可以去maven官网手动下载
在这里插入图片描述

在对应目录下,将下载后的jar 包放进来
在这里插入图片描述

② 手动创建缺失的文件目录
在这里插入图片描述

5、导入源码

在这里插入图片描述
在这里插入图片描述

6、添加测试模块代码

new -> model -> gradle -> 输入模块名称
在这里插入图片描述

build.gradle 添加依赖

dependencies {
    testCompile group: 'junit', name: 'junit', version: '4.12'
    compile(project(":spring-context"))
}

添加测试类

package com.tuling;

import org.springframework.stereotype.Service;
@Service
public class UserServiceImpl {
   public void say(){
      System.out.println("Hello YinPengHai!");
   }
}

添加启动类

import com.tuling.UserServiceImpl;
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.tuling")
public class MainStat {
    public static void main(String[] args) {
        ApplicationContext context = new AnnotationConfigApplicationContext(MainStat.class);
      UserServiceImpl bean = context.getBean(UserServiceImpl.class);
      bean.say();
   }

}

遇到如下问题,点击右下角红色感叹号,根据提示将插件卸载即可

在这里插入图片描述

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值