深入理解Spring源代码-开头篇

开篇 

    最近想来研究研究下spring的源代码,在此之前都是使用其部分的功能,比如springmvc,事务管理等,并未对其内部的原理进行研究过,对于这么一个经常使用的开源框架  得好好的去学习它里面的一些设计原理和思想,对自己来说也是一个进步。

 目前使用的是spring3.2.2的版本,那么就拿这个版本来学习吧。


目录:

1.下载源代码

2.一个简单的HelloWorld示例

3.如何阅读源码


如何下载源代码:

   https://github.com/SpringSource/spring-framework

选择对应的版本即可

jar的选择:

可以暂时将所有的spring包都添加进来


第一个包commons-logging是必需的,没有的话,运行会抛出异常,将这些包都导入到工程的classpath路径下


helloWorld 示例 :

package org.spring.read.read01;

public class HelloWorld {

	private String name = null;

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
}
package org.spring.read.read01;

import org.springframework.context.support.ClassPathXmlApplicationContext;

public class Main {

	public static void main(String[] args) {
	 
		ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("classpath:spring.xml");
		HelloWorld helloWord = (HelloWorld)context.getBean("helloWord");
		System.out.println(helloWord.getName());

	}

}

配置文件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:aop="http://www.springframework.org/schema/aop"  
    xmlns:tx="http://www.springframework.org/schema/tx"  
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc"  
    xsi:schemaLocation="   
          http://www.springframework.org/schema/beans   
          http://www.springframework.org/schema/beans/spring-beans-3.2.xsd   
          http://www.springframework.org/schema/tx   
          http://www.springframework.org/schema/tx/spring-tx-3.2.xsd  
          http://www.springframework.org/schema/context   
          http://www.springframework.org/schema/context/spring-context-3.2.xsd   
          http://www.springframework.org/schema/aop   
          http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
          http://www.springframework.org/schema/mvc
          http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd">
     
    <bean id="helloWord" class="org.spring.read.read01.HelloWorld">
       <property name="name">
         <value>hello World</value>
       </property>
    </bean>
     
</beans>


将spring.xml文件放入src根目录下



如何关联源代码:


右键选中当前工程spirng,Build Path->Configure Build Path->







选择相应的source源码包路径


设置完成之后,可以采用单步调试的方法进行源代码




















  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值