spring源码阅读环境搭建

spring源码阅读环境搭建

目录

使用工具jdk1.8 和eclipse

第一步

下载spring源码,git地址https://github.com/spring-projects/spring-framework ,可以使用git下载也可以去网页里下载zip,git速度有点慢我下载的是zip,版本选的是5.0
在这里插入图片描述

第二步

进入解压后的文件夹,找到import-into-eclipse.bat,运行它
在这里插入图片描述
按照提示按任意键继续
在这里插入图片描述
具体图就不再截取了,就这样一直执行下去就好了,然后就可以导入eclipse

第三步

eclipse导入项目
在这里插入图片描述
会遇到的错误
1.jdk版本选择 (这个比较大众不说了)
2.groovey版本问题
解决方式是:
1.再报错的项目上右键 properties
2.选择groovy compiler 修改版本
在这里插入图片描述
项目导入之后把jdk换成了jdk8,然后修改了groovey版本,最后就成功了,报错修改如果有问题的可以评论我

在这里插入图片描述

测试

下面属于测试项目
在这里插入图片描述
此处不做详解
InstantC.java

import org.springframework.stereotype.Component;

@Component
public class InstantC {
	public InstantC(){
		System.out.println("ic的构造器被调用了");
	}
	public void print() {
		System.out.println("ic的bean使用");
	}
}

MainConfigure.java

import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportResource;

@Configuration
@ImportResource(locations="classpath:spring.xml")
@ComponentScan(basePackages= {"com.zk.test"})
public class MainConfigure {

}

Main .java

import org.springframework.context.annotation.AnnotationConfigApplicationContext;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		//上下文 创建IOC容器
		AnnotationConfigApplicationContext ctx=new AnnotationConfigApplicationContext(MainConfigure.class);
		//获取bean  去容器的缓存中直接拿
		InstantC instantC=(InstantC) ctx.getBean("ic");
		ctx.close();
	}

}

spring.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" 
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context 
        http://www.springframework.org/schema/context/spring-context.xsd 
        http://www.springframework.org/schema/tx 
        http://www.springframework.org/schema/tx/spring-tx.xsd">
	<bean id="ic" class="com.demo.InstantC"></bean>
</beans>

然后是运行结果
在这里插入图片描述

想要debug看源码的小伙伴就可以进入代码里面debug了,希望对您能有帮助。。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值