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/beanshttp://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,如上圖;
總結
以上是生活随笔為你收集整理的spring 源码阅读入门的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 图解使用Ant构建一个Java项目
- 下一篇: java swing 例子(一些)