Spring之二 Bean

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>






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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值