Spring源码解析

  通过搭建最基本的Spring的maven项目:

1.需要的jar

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>4.0.5.RELEASE</version>
    </dependency>

2.基本的配置文件:spring-demo.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" 
        default-init-method="defautInit" default-destroy-method="defaultDestroy">
        
        <bean id="beanDemo" class="com.springdemo.BeanDemo" ></bean>
</beans>

3.一个bean对象:

package com.springdemo;

public class BeanDemo {
	
	public String name="hello";

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
	
	public void say(){
		System.out.println("this is "+this.getName());
	}

}

4.一个测试类:

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

public class Test {

	public static void main(String[] args) {
		ApplicationContext ctx = 
				new ClassPathXmlApplicationContext("classpath:spring-demo.xml");
		
		BeanDemo blc= (BeanDemo) ctx.getBean("beanDemo");
		blc.say();

	}

}

5.结果:


十月 28, 2015 6:00:18 下午 org.springframework.context.support.ClassPathXmlApplicationContext prepareRefresh

INFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@75f9eba0: startup date [Wed Oct 28 18:00:18 CST 2015]; root of context hierarchy

十月 28, 2015 6:00:18 下午 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions

INFO: Loading XML bean definitions from class path resource [spring-demo.xml]

this is hello

6:然后,就是探索Spring源码的开始。。。。。。

你可能感兴趣的:(Spring源码解析)