3.1 Bean的配置

Bean的配置示例代码如下:

<?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">
        
	<!-- 使用id属性定义myTestDIDao,其对应的实现类为dao.TestDIDaoImpl-->
	<bean id="myTestDIDao" class="dao.TestDIDaoImpl" />
	
	<!-- 使用构造方法注入 -->
	<bean id="testDIService" class="service.TestDIServiceImpl">
	
	<!--给构造方法传引用类型的参数值myTestDIDao-->
		<constructor-arg index="0" ref="myTestDIDao"/>
	</bean>
</beans>


属性或子元素名称描述
idBean在BeanFactory中唯一的标识
classBean的具体实现类,使用类的名(例如dao.TestDIDaoImpl)
scope指定Bean实例的作用域
< constructor >使用构造方法注入。该元素的index属性指定参数的序号,ref属性指定对BeanFactory中其他Bean的引用关系
< property >用于设置一个属性,该元素的name属性指定Bean实例中相应的属性名称,value属性指定Bean的属性值,ref属性指定属性对BeanFactory中其他Bean的引用关系。
< list >< property >的子元素,用于封装List或数组类型的依赖注入。
< set >< property >的子元素,用于封装Set类型的依赖注入
< map >< property >的子元素,用于封装Map类型的依赖注入
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值