Spring 6.x源码编译
环境
- Windows 10
- IntelliJ IDEA 2023.1.2 (Ultimate Edition)
- jdk-17.0.7 Spring6要求jdk17+
创建init.grade文件
相当于maven的settings.xml,全局加速拉取依赖
allprojects {
repositories {
mavenLocal()
maven { url "https://maven.aliyun.com/repository/public" }
maven { url 'https://maven.aliyun.com/repository/central' }
maven { url 'https://maven.aliyun.com/repository/google' }
maven { url 'https://maven.aliyun.com/repository/google' }
maven { url 'https://maven.aliyun.com/repository/spring' }
maven { url 'https://maven.aliyun.com/repository/grails-core' }
maven { url 'https://maven.aliyun.com/repository/apache-snapshots' }
jcenter()
mavenCentral()
}
buildscript {
repositories {
mavenLocal()
maven { url 'https://maven.aliyun.com/repository/public' }
maven { url 'https://maven.aliyun.com/repository/central' }
maven { url 'https://maven.aliyun.com/repository/gradle-plugin' }
maven { url 'https://maven.aliyun.com/repository/spring-plugin' }
jcenter()
mavenCentral()
}
}
}
导入工程,修改gradle对应的jdk版本
设置工程jdk
Build
由于一开始设置过gradle依赖的全局加速,所以从阿里云拉取依赖
依赖下载完毕
分别执行
创建测试代码
在spring-test新建包study
- TestServiceImpl.java
package org.springframework.test.study;
import org.springframework.stereotype.Component;
@Component
public class TestServiceImpl {
public void hello() {
System.out.println("hello");
}
}
- TestSpring.java
package org.springframework.test.study;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
public class TestSpring {
public static void main(String[] args) {
ApplicationContext context = new AnnotationConfigApplicationContext("org.springframework.test.study");
context.getBean(TestServiceImpl.class).hello();
}
}
运行main,执行结果如下: