一、提前编译好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,开发期发行版本,边开发变发行;