1. 安装gradle
1.1 解压gradle
解压gradle安装包 (gradle-6.5-bin.zip)
1.2 配置环境变量
GRADLE_HOME : D:\Program Files\gradle-6.5(gradle路径)
Path : %GRADLE_HOME%\bin
GRADLE_USER_HOME : D:\apache-maven-3.2.3\repository(仓库路径)
1.3 验证是否安装成功 (win10貌似需要重启,环境变量才生效)
gradle -version
2. 解压源码包
spring源码包,内有我写的一些注释。
链接:https://pan.baidu.com/s/1JyfxUOW0QY2Q5VuGiZuE8g
提取码:ev3n
3. idea配置源码
3.1 idea配置gradle
3.2 导入gradle项目
3.2.1 File -> open
3.2.2 Open as Project
3.2.3 导入项目
3.2.4 编译
3.2.5 build
build 时如果失败,则多刷新几次,下载jar包速度较慢,时间可能会很长。
3.2.6 编译成功后
4. 测试类测试
import org.springframework.context.annotation.ComponentScan;
@ComponentScan("test")
public class Config {
}
import org.springframework.stereotype.Component;
@Component
public class UserService {
public UserService(){
System.err.println(" userService 构造方法 ");
}
public void test() {
System.err.println(" userService test ");
}
}
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import test.service.UserService;
public class TestClient {
public static void main(String[] args) {
AnnotationConfigApplicationContext cf = new AnnotationConfigApplicationContext(Config.class);
UserService userService = cf.getBean(UserService.class);
userService.test();
}
}