一、提前編譯好Spring源碼
1、安裝JDK、idea、maven並做好響應的配置;
2、下載源碼並編譯;
Y004番外教程-編譯Spring框架-JDK13 + spring-framework v5.2.4.RELEASE + git
二、導入IDEA
直接主界面Import Project,選擇spring-framework文件夾,IDEA經過一段時間的下載,就能導入成功;
三、排除 spring-aspects 模塊
四、創建springdemo
第一步:、
第二步:
第三步:
五、測試代碼
六、第一個springdemo
1、代碼
IWelcomeService接口:
package com.zibo.service;
public interface IWelcomeService {
String sayHello(String name);
}
WelcomeServiceImpl接口實現類:
package com.zibo.service.impl;
import com.zibo.service.IWelcomeService;
public class WelcomeServiceImpl implements IWelcomeService {
@Override
public String sayHello(String name) {
System.out.println("Hello " + name);
return "success";
}
}
Entrance測試類:
package com.zibo;
import com.zibo.service.IWelcomeService;
import org.springframework.context.support.FileSystemXmlApplicationContext;
public class Entrance {
public static void main(String[] args) {
//配置文件絕對路徑
String xmlPath = "D:\\Spring\\spring-framework\\springdemo\\src\\main\\resources\\spring\\spring-config.xml";
//讀取配置文件
FileSystemXmlApplicationContext context = new FileSystemXmlApplicationContext(xmlPath);
//從配置文件中取出welcomeService
IWelcomeService welcomeService = (IWelcomeService) context.getBean("welcomeService");
//調用welcomeService的方法
welcomeService.sayHello("ZiBo");
}
}
spring-config.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 id="welcomeService" class="com.zibo.service.impl.WelcomeServiceImpl"/>
</beans>
build.gradle:
plugins {
id 'java'
}
group 'io.spring.asciidoctor'
version '5.2.5.BUILD-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
compile(project(":spring-context"))
testCompile group: 'junit', name: 'junit', version: '4.12'
}
2、文件結構圖
3、運行結果
七、學好Spring源碼的建議
1、閱讀Spring官方文檔(Spring的文檔非常詳盡);
2、多動手調試;
3、掌握設計模式,熟悉spring框架的標籤和註解的作用;
八、軟件版本知識點補充
1、GA:General Availability,官方正式發佈的穩定版本;
2、同質的還有RELEASE,Stable,Final
3、RC:Release Candidate,發行候選版本,基本不再加入新的功能;
4、Alpha:內部測試版,bug較多,功能不全;
5、Beta:公開測試版,比Alpha版本晚些,還會加功能,修bug;
6、M:Milestone,開發期發行版本,邊開發變發行;