S002《剑指Java自研框架,决胜Spring源码》第一章:环境准备(2)Spring的源码下载和编译

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

 

 

 

 

 

 

 

 

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值