1、下载源码包
Spring 官网
下载
2、修改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" }
}
3、解压后在当前目录输入cmd
gradlew :spring-oxm:compileTestJava
只要看到 BUILD SUCCESSFUL 表示编译成功
4、编译遇到的问题
① 编译过程中遇到下载jar包失败,可以去maven官网手动下载
在对应目录下,将下载后的jar 包放进来
② 手动创建缺失的文件目录
5、导入源码
6、添加测试模块代码
new -> model -> gradle -> 输入模块名称
build.gradle 添加依赖
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
compile(project(":spring-context"))
}
添加测试类
package com.tuling;
import org.springframework.stereotype.Service;
@Service
public class UserServiceImpl {
public void say(){
System.out.println("Hello YinPengHai!");
}
}
添加启动类
import com.tuling.UserServiceImpl;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
@Configuration
@ComponentScan("com.tuling")
public class MainStat {
public static void main(String[] args) {
ApplicationContext context = new AnnotationConfigApplicationContext(MainStat.class);
UserServiceImpl bean = context.getBean(UserServiceImpl.class);
bean.say();
}
}
遇到如下问题,点击右下角红色感叹号,根据提示将插件卸载即可