idea中spring-5.2.11源码搭建

本文介绍了如何搭建基于Spring Framework 5.2.11和Gradle 5.6.4的开发环境,包括下载JDK 1.8.0和指定版本的Spring Framework,修改Gradle镜像源,配置并编译Spring工程。通过示例代码展示了从创建AppConfig、HelloService到启动程序的完整流程,强调了版本匹配和网络条件对构建过程的影响。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

环境准备

  • jdk1.8.0
  • spring-framework-5.2.11.RELEASE 下载地址 https://github.com/spring-projects/spring-framework (注意下载版本,不需要下载最新的;
  • gradle v5.6.4 下载地址 https://gradle.org/releases/ (注意版本,这个版本和spring-framework5.2.11是搭配的)

修改镜像

将spring工程下的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" }
		}

编译compileTestJava模块

配置好gradle的文件,执行

gradle :spring-oxm:compileTestJava

常见问题

1.企业版的一个包下载不了
在这里插入图片描述
解决方法(亲测)
将 build.gradle文件中的配置注释掉
在这里插入图片描述

成功

如果失败,再重试几次
在这里插入图片描述

导入idea

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
配置idea,导入后等待编译,需要一定的时间

测试代码

选择file-> module -> Gradle -> 起名
在这里插入图片描述
在这里插入图片描述
AppConfig

@ComponentScan(value = "com.jzc")
public final class AppConfig {
}

HelloService

@Service
public class HelloService {

	public void test(){
		System.out.println("Hello Spring!");
	}
}

Start

public class Start {

	public static void main(String[] args) {

		AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(AppConfig.class);

		HelloService helloService = (HelloService) context.getBean("helloService");

		helloService.test();

	}

}

build.gradle文件

plugins {
    id 'java'
}

group 'org.springframework'
version '5.2.11.RELEASE'

repositories {
    mavenCentral()
}

dependencies {
    compile(project(":spring-jdbc"))
    compile(project(":spring-context"))
    compile(project(":spring-aop"))
//    compile(project(":spring-web"))
    
}
test {
    useJUnitPlatform()
}

启动
在这里插入图片描述
大功告成!!!

注意点:
版本要一致gradle和spring版本是对应的
网速好,不然很多依赖下载不了

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值