本文介紹使用IntelliJ IDEA搭建Spring Framework源代碼環境,用于源代碼閱讀與debug。
創新互聯公司網站建設由有經驗的網站設計師、開發人員和項目經理組成的專業建站團隊,負責網站視覺設計、用戶體驗優化、交互設計和前端開發等方面的工作,以確保網站外觀精美、成都網站設計、網站制作、外貿營銷網站建設易于使用并且具有良好的響應性。
訪問Spring Framework在GitHub的地址,下載最新源代碼。本人在下載時,版本號為5.2.2.BUILD-SNAPSHOT
https://github.com/spring-projects/spring-framework
根據源代碼文件中的IDEA導入說明進行操作,說明文件為源代碼根目錄的import-into-idea.md
Precompile `spring-oxm` with `./gradlew :spring-oxm:compileTestJava`
Import into IntelliJ (File -> New -> Project from Existing Sources -> Navigate to directory -> Select build.gradle)
When prompted exclude the `spring-aspects` module (or after the import via File-> Project Structure -> Modules)
Code away
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>cn.daiwuliang</groupId>
<artifactId>demo</artifactId>
<version>1.0-SNAPSHOT</version>
<name>demo</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<!-- 引入commons-logging依賴 -->
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.2</version>
</dependency>
</dependencies>
<build>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
<!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.7.1</version>
</plugin>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.0.0</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
package demo.test;
public class TestDemo {
public String test(String str) {
return String.format("ECHO: %s", str);
}
}
package demo.test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
public class App {
public static void main(String[] args) {
String XMLPath = "D:\\spring-framework-master\\demo\\src\\main\\java\\demo\\test\\spring-config.xml";
ApplicationContext applicationContext = new FileSystemXmlApplicationContext(XMLPath);
TestDemo td = (TestDemo) applicationContext.getBean("testDemo");
System.out.println(td.test("Hello World!!!"));
}
}
<?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 id="testDemo" class="demo.test.TestDemo"/>
</beans>
dependencies {
......
compile("commons-logging:commons-logging:1.2")
}
至此,運行App中的main方法,得到以下結果:
Hello World!
文章名稱:SpringFramework源代碼環境搭建
文章源于:http://vcdvsql.cn/article32/gjispc.html
成都網站建設公司_創新互聯,為您提供全網營銷推廣、App開發、品牌網站設計、外貿網站建設、網站內鏈、Google
聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯