请参考http://ajava.org/online/spring2.5s/html_single/#preface
下面是对Spring最基本的知识的学习笔记:
1.BeanFactory是IoC容器的核心接口,是Spring IoC容器的实际代表者。 它的职责包括:实例化、定位、配置应用程序中的对象及建立这些对象间的依赖。ApplicationContext 是BeanFactory的扩展.
2.实例化容器:
(1)ApplicationContext context = new ClassPathXmlApplicationContext(
new String[] {"services.xml", "daos.xml"});
// an ApplicationContext is also a BeanFactory (via inheritance)
BeanFactory factory = context;
(2)Resource res = new FileSystemResource("beans.xml");
BeanFactory factory = new XmlBeanFactory(res);
使用getBean(String) 方法就可以取得bean的实例;BeanFactory 提供的方法极其简单。 BeanFactory接口提供 了非常多的方法,但是对于我们的应用来说,最好永远不要调用它们,当然也包括 使用getBean(String)方法,这样可以避免我们对 Spring API的依赖
3.实例化bean
(1).用构造器来实例化:
<bean id="exampleBean" class="examples.ExampleBean"/>
(2).使用静态工厂方法实例化
<bean id="exampleBean"
class="examples.ExampleBean2"
factory-method="createInstance"/>
(3).使用实例工厂方法实例化
<bean id="exampleBean"
factory-bean="serviceLocator"
factory-method="createInstance"/>
虽然设置bean属性 的机制仍然在这里被提及,但隐式的做法是由工厂bean自己来管理以及通过依 赖注入(DI)来进行配置。
4.注入依赖:DI主要有两种注入方式,即Setter注入和构造器注入.由于大量的构造器参数可能使程序变得笨拙,特别是当某些属性是可选的时候。因此通常情况下,提倡使用setter注入.
5.集合:通过<list/>、<set/>、<map/>及<props/>元素可以定义和设置与Java Collection类型对应List、Set、Map及Properties的值。
6.生命周期回调
Spring提供了几个标志接口(marker interface),这些接口用来改变容器中bean的行为;它们包括InitializingBean和DisposableBean。实现这两个接口的bean在初始化和析构时容器会调用前者的afterPropertiesSet()方法,以及后者的destroy()方法。
7.用BeanPostProcessor定制bean
8.PropertyPlaceholderConfigurer
9.messageSource国际化
10.AOP