Table of Contents
spring导入IDEA
基础环境
- spring 5.3.x
- JDK 1.8
- Gradle 7.5
gradle -version 命令查看gradle版本;
java -version jdk版本信息
代码准备
从github上下载spring代码,切换分支到 5.3.x版本
查看import-into-idea.md文件内容,执行gradlew spring-oxm:compileTestJava
执行完成后可将代码导入到Idea
代码导入Idea
idea -> File -> Open 打开spring代码文件夹,导入到Idea
修改Idea-gradle配置
在spring代码中新增自己的module
打开Idea Project Structure
修改自己module的 gradle文件配置
plugins {
id 'java-library'
}
group 'org.springframework'
version '5.3.24-SNAPSHOT'
repositories {
mavenCentral()
}
dependencies {
api(project(":spring-aop"))
api(project(":spring-beans"))
api(project(":spring-context"))
api(project(":spring-core"))
api(project(":spring-expression"))
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.2'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.2'
}
test {
useJUnitPlatform()
}
注意plugins id 配置为 java-library#
测试代码
SimpleBean.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean class="com.jingu.study.SimpleBean"/>
</beans>
SimpleBeanSpring.java
public class SimpleBeanSpring {
public static void main(String[] args) {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("SimpleBean.xml");
SimpleBean bean = context.getBean(SimpleBean.class);
bean.send();
context.close();
}
}
SimpleBean.java
public class SimpleBean {
public void send() {
System.out.println("I am send method from SimpleBean!");
}
}