利用Gradle编译Spring

先从github下载Spring

https://github.com/spring-projects/spring-framework
然后选择版本,此处用5.2.7RELEASE
在这里插入图片描述

构造工具

GradleWraper中的Gradle:
Gradle在spring-framework-5.2.7.RELEASE\gradle\wrapper\gradle-wrapper.properties文件中有,相当于远程自动下载gradle到本地。

修改build.gradle :
这个文件就相当于我们Maven的pom.xml 管理项目的依赖等

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模块
打开源码所在文件夹,在windows cmd命令中输入

gradlew :spring-oxm:compileTestJava

在这里插入图片描述
成功后,导入项目到idea中
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

导入后等待编译
在这里插入图片描述
添加测试模块代码:

new->model->gradle–>输入模块名称
添加依赖

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

compile(project(":spring-context")) 代表本项目的

随意添加任意bean

@Service
public class MyServiceImpl {
	public void say(){
		System.out.println("hello world");
	}
}

启动

@Component
@ComponentScan("com.test")
public class Test {
	public static void main(String[] args) {
		ApplicationContext applicationContext = new AnnotationConfigApplicationContext(Test.class);
		MyServiceImpl bean = (MyServiceImpl)applicationContext.getBean("myServiceImpl");
		bean.say();
	}
}

成功输出
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值