1、IOC实例化
BeanFactory: IOC 容器的基本实现.
ApplicationContext: 提供了更多的高级特性. 是 BeanFactory 的子接口.
BeanFactory 是 Spring 框架的基础设施,面向 Spring 本身;
ApplicationContext 面向使用 Spring 框架的开发者,几乎所有的应用场合都直接使用 ApplicationContext 而非底层的 BeanFactory
ApplicationContext 的主要实现类:
ConfigurableApplicationContext 扩展于 ApplicationContext,新增加两个主要方法:refresh() 和 close(), 让 ApplicationContext 具有启动、刷新和关闭上下文的能力ClassPathXmlApplicationContext:从 类路径下加载配置文件
FileSystemXmlApplicationContext: 从文件系统中加载配置文件
2、依赖注入
1)属性值注入
<bean id="helloWorld" class="com.ithings.HelloWorld">
<property name="userName" value="tom"></property>
</bean>
2)构造方法注入
<bean id="helloWorld" class="com.ithings.HelloWorld">
<constructor-arg value="BYD" index="1"></constructor-arg>
<constructor-arg value="一汽" index="2"></constructor-arg>
</bean>
3)引用其他bean
<bean id="helloService" class="com.ithings.service.HelloService">
</bean>
<bean id="helloAction" class="com.ithings.action.HelloAction">
<property name="helloService" ref="helloService"></property>
</bean>