spring 源码阅读入门

spring和源码3.0.5下载

http://download.csdn.net/download/haluoyimo/7752753

http://pan.baidu.com/s/1qYnK784


参考文章

http://www.cnblogs.com/xing901022/p/4178963.html


首先新建一个Java项目;



解压后的spring包是如下的结构;


dist内是发布的包;


src内是对应的源码包;


项目属性导入全部的dist下的包,还有mysql-connector,commons-logging等;完成后如下图;

或者光导入项目用到的包也可;



点开一个导入的spring dist包,点击Source attachment,点击 Edit 按钮;



添加源码包的路径,即src下的包的路径;如下图;

发布包和源码包一个个对应的;



添加好之后如下;





完成上述后项目结构如下;



新建如下的包,类,文件;


代码;

Person.java

package com.test.bean;
 
public class Person {
    
    private String name;
    private int age;
    
    public String getName() {
        return name;
     }
     public void setName(String name) {
         this.name = name;
     }
     public int getAge() {
         return age;
     }
     public void setAge(int age) {
         this.age = age;
     }
     public void info(){
         System.out.println("name:"+getName()+" age:"+getAge());
     }
 }

test.java

package testSpring;
 
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.test.bean.Person;

public class test {
    public static void main(String[] args){
        ApplicationContext ctx = new ClassPathXmlApplicationContext("bean.xml");//读取bean.xml中的内容
        Person p = ctx.getBean("person",Person.class);//创建bean的引用对象
        p.info();
    }
}

bean.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://www.springframework.org/schema/beans"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
    <bean id="person" class="com.test.bean.Person">
        <property name="name" value="xingoo"/>
        <property name="age" value="12"/>
    </bean>
</beans>

项目运行结果如下;


ApplicationContext ctx = new ClassPathXmlApplicationContext("bean.xml");//读取bean.xml中的内容
Person p = ctx.getBean("person",Person.class);//创建bean的引用对象

这两句下断点;然后开始debug;


停留在断点;



打F5,进入下一个函数;进到spring源码了;因为前面附着了spring源码包,对应的spring源码函数显示出来;



F5,下一个函数;


F5,下一个函数;


F5,下一个函数;


F5,下一个函数;


F5,下一个函数;

看到一列的函数调用,这个就是传说中的栈帧了;


如果进到没有附着源码的函数,则会提示Source not found,如上图;


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值