Idea导入SpringBoot源码终极版(基于Gradle)

一、导入Spring源码的准备

  • 本人工具及环境介绍
    Windows 10 + IDEA 2020.1 + JDK 11.0.9 + Gradle 6.5 + spring-boot 2.5.0-SNAPSHOT

1.1 Gradle的下载和配置

  • 官网地址
    https://gradle.org/releases/
  • 版本选择
    找到对应的版本,选择 binary-only
    在这里插入图片描述
  • 配置环境变量
    解压后,别放中文路径兄弟
    ① 新建系统变量 GRADLE_HOME
    在这里插入图片描述
    ② 新建仓库系统变量 GRADLE_USER_HOME
    在这里插入图片描述
    path 中添加 %GRADLE_HOME%\bin
    在这里插入图片描述
    ④ 检查是否配置成功
    gradle -v
    在这里插入图片描述

1.2 IDEA集成Gradle

  • 依次执行如下步骤
    Settings -> Build -> Gradle
    在这里插入图片描述

1.3 下载SpringBoot源码

  • 下载方式
    ① 下载源码 zip 包,然后导入,不建议
    ② 从 GitHub 上检出源码,不仅能及时更新代码,还有很清楚的代码更新记录,岂不是爽歪歪
    https://github.com/spring-projects/spring-boot
    在这里插入图片描述
    在这里插入图片描述

二、导入及避坑

2.1 导入源码

  • 源码包导入步骤(如果是通过代码检出的方式请忽略此步骤)
    ① 在 Idea 中依次 File -> Open
    ② 找到源码包文件夹,并选择 build.gradle
    在这里插入图片描述

2.2 避坑的地方

  • 为了防止build 的过程很慢,检查Idea的运行内存并调整
    ① 修改配置文件
    在这里插入图片描述
    ② 修改运行内存
    在这里插入图片描述
  • 依赖下载很慢的问题
    我下载的速度很慢,按照 网上说的调整了镜像似乎什么用都没有,每次出现下载失败的问题,直接重新 build 就好

三、增加测试模块试运行

3.1 新建测试模块

  • 新建测试模块
    ① 新建Gradle 模块
    在这里插入图片描述
    ② 配置 locatiionname
    在这里插入图片描述
  • 配置当前模块的 build.gradle
    在这里插入图片描述
plugins {
    id 'java'
}

group 'org.springframework.boot'
version '2.5.0-SNAPSHOT'

repositories {
    mavenCentral()
}

dependencies {
    annotationProcessor(project(":spring-boot-project:spring-boot-tools:spring-boot-configuration-processor"))
    implementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-web"))
    implementation(enforcedPlatform(project(":spring-boot-project:spring-boot-dependencies")))
    implementation(project(":spring-boot-project:spring-boot"))
    implementation("jakarta.validation:jakarta.validation-api")
}
  • 创建测试demo
    在这里插入图片描述
package org.springframework.debug;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author: yangbh29924
 * @date: Dec 26, 2020
 **/
@RestController
@EnableAutoConfiguration
@SpringBootConfiguration
public class DemoApplication {

	public static void main(String[] args) {
		SpringApplication.run(DemoApplication.class, args);
	}

	@GetMapping("/hello")
	public String hello(@RequestParam(value = "name", defaultValue = "World") String name) {
		return String.format("Hello %s!", name);
	}


}

  • 运行并测试
    在这里插入图片描述
    在这里插入图片描述
  • 3
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值