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"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="abstractIphone" class="com.yaspeed.spring.bean.cycle.Iphone7"
p:name="iphone7" p:price="7188" <span style="color:#FF0000;">abstract="true"</span>></bean>
<bean id="iphone7" class="com.yaspeed.spring.bean.cycle.Iphone7" init-method="init"
destroy-method="cleanUp" parent="abstractIphone">
</bean>
</beans>
依赖配置
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="iphone7" class="com.yaspeed.spring.bean.cycle.Iphone7"
p:name="iphone7" p:price="7188" ></bean>
<bean id="iphone7Plus" class="com.yaspeed.spring.bean.assembly.Iphone7Plus"
depends-on="iphone7">
</bean>
</beans>引用配置
<bean id="service" class="com.atguigu.spring.ref.Service">
<!-- 通过 ref 属性值指定当前属性指向哪一个 bean! -->
<property name="dao" ref="dao5"></property>
</bean>
本文介绍了Spring框架中Bean的三种配置方式:继承配置、依赖配置和引用配置,并通过具体示例展示了如何实现这些配置。
1583

被折叠的 条评论
为什么被折叠?



