- 环境
idea 2021社区版
jdk8 - 下载spring源码
a、git上下载spring5.2.7 zip包,解压缩
b、修改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" } }
c、下载gradle-5.6.4-bin.zip
d、修改gradlewrapper 目录下的gradle-wrapper.properties,注释掉原distributionUrl配置,以免从网上下载gradle。
#distributionUrl=https://services.gradle.org/distributions/gradle-5.6.4-bin.zip
distributionUrl=file:///D:/.gradle/wrapper/dists/gradle-5.6.4-bin.zipe、编译compileTestJava模块
执行gradlew.bat或在spring源码根目录里运行windows cmd,执行以下命令
gradlew :spring-oxm:compileTestJava
配置了镜像一般很快(1-3)分钟就能完成,如果要很久说明镜像配置不成功
3. 导入idea
Import into IntelliJ (File -> New -> Project from Existing Sources -> Navigate to directory -> Select build.gradle)
idea配置:
导入后编译需要一段时间。
4 添加测试模块
new->model->gradle-->输入模块名称
@Service public class TestImpl { public void hello(){ System.out.println("Hello Spring!"); } }
@Configuration @ComponentScan("com.test") public class TestClass { public static void main(String[] args) { ApplicationContext context=new AnnotationConfigApplicationContext(TestClass.class); TestImpl bean = context.getBean(TestImpl.class); bean.hello(); } }
5 大功告成