一、 下載Gradle
Gradle官網下載:https://gradle.org/install/
Gradle 6.0 鏈接:https://pan.baidu.com/s/1JUdVNVTc8uVF0vNjEbNQ2A
提取碼:l2ky
配置環境變量
新建GRADLE_HOME,Gradle 6.0解壓縮文件夾地址
編輯path, 新建%GRADLE_HOME%\bin
查看安裝結果
win+r --> cmd--> gradle -v
注意:gradle 要 JDK8 的版本
二、下載spring5.1.3源碼
git下載地址
git clone --branch v5.1.3.RELEASE https://gitee.com/Z201/spring-framework.git
三、idea中使用gradle 配置spring源碼環境(根據下圖進行配置)
配置Gradle VM options:-XX:MaxPermSize=2048m -Xmx2048m -XX:MaxHeapSize=2048m
在 idea --> Terminal 中執行gradlew :spring-oxm:compileTestJava
環境創建成功,創建bean
package com.kelley.bean; import org.springframework.stereotype.Service; @Service public class Student { private String username = "kelley"; public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } }
創建測試類
package com.kelley.test; import com.kelley.bean.Student; import org.junit.Test; import org.springframework.context.support.ClassPathXmlApplicationContext; public class Mytest { @Test public void test1() { ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("spring.xml"); Student student = (Student)applicationContext.getBean("student"); System.out.println(student.getUsername()); } }
test --> resource-->spring.xml
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd ">
<context:component-scan base-package="com.kelley"/>
</beans>
運行結果
環境測試完畢!