spring源码深入阅读分析---环境搭建(二)

spring源码阅读环境搭建

一、我的环境
1、系统版本
MacOS 10.15.2
2、开发版本工具
spring-framework-5.0.x.RELEASE
gradle4.9
jdk1.8.0_121
IntelliJ IDEA 2019
假设以上软件都已安装完成。
二、源码下载
1、地址
https://github.com/spring-projects/spring-framework/tags

2、下载完成直接解压到合适的目录即可

3、导入idea

在这里插入图片描述spring是Gradle编译的,所以选择Gradle项目导入。

在这里插入图片描述

三、源码编译
1、点击gradle的Refresh按钮

在这里插入图片描述
可能会报一些错,可以自行百度进行解决

2、编译开始(执行图中所示的步骤1和步骤2)

依次编译spring-core,spring-oxm,spring-context,spring-bean即可。

四、编写调试demo1在这里插入图片描述
在这里插入图片描述

在这里插入图片描述
在这里插入图片描述
一路next,直到finish即可。

编写demo开始,添加工程依赖
在这里插入图片描述
测试类

@SuppressWarnings("deprecated")
public class BeanFactoryTest {

	@Test
	public void testLoad(){

		//方式1,使用XmlBeanFactory方式进行加载
		Resource resource= new ClassPathResource("beanFactoryTest.xml");
		BeanFactory bf = new XmlBeanFactory(resource);
		MyTestBean myTestBean = (MyTestBean)bf.getBean("myTestBean");


		//方式2, 使用ApplicationContext方法进行加载,applicationContext包含了beanFactory中的所有方法,并对功能进行了扩展
		//ApplicationContext applicationContext = new ClassPathXmlApplicationContext("beanFactoryTest.xml");
		//MyTestBean myTestBeanbak = (MyTestBean)applicationContext.getBean("myTestBean");



		System.out.println(myTestBean.getTestStr());

	}
}

配置文件beanFactoryTest.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="myTestBean" class="bean.myFactory.MyTestBean"/>

	<bean id="getBeanTest" class="bean.myFactory.user.GetBeanTest">
		<lookup-method name="getBean" bean="teacher"></lookup-method>
	</bean>

	<bean  id="teacher" class="bean.myFactory.user.Teacher"></bean>

	<bean id="testChangeMethod" class="bean.myFactory.replaced_method.TestChangeMethod">
		<replaced-method name="changeMe" replacer="replacer"></replaced-method>
	</bean>

	<!--测试事件监听-->
	<bean id="testListener" class="bean.myFactory.event.TestListener"/>

	<bean id="replacer" class="bean.myFactory.replaced_method.TestMethodReplacer"></bean>
</beans>

至此,阅读源码的环境已经完成。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值