环境准备
- 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版本是对应的
网速好,不然很多依赖下载不了