Spring初学之bean之间的关系和bean的作用域
2024-09-06 23:31:25
一、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="car" class="spring.beans.autowire.Car"
p:carName="奥迪^" p:price="300000"></bean> <!-- 继承 -->
<bean id="car2" class="spring.beans.autowire.Car"
p:price="100000" parent="car"></bean> <!-- 抽象类 -->
<bean id="address1" p:city="重庆" abstract="true"></bean> <bean id="address" class="spring.beans.autowire.Address"
p:more="梁平" parent="address1"></bean> <!-- 依赖 -->
<bean id="person" class="spring.beans.relation.Person" p:name="张三" p:car-ref="car"
depends-on="address" p:address-ref="address">
</bean> </beans>
二、bean的作用域
常用的两个作用域就是scope="singleton"和scope="prototype"
<?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"> <!-- bean的作用域 scope-->
<bean id="car" class="spring.beans.scope.Car" scope="prototype">
<property name="name" value="奥迪"></property>
<property name="price" value="300000"></property>
</bean> </beans>
最新文章
- 警惕自己,不断学习c++【转】
- centos7 gitlab
- POJ 1094 Sorting It All Out 拓扑排序 难度:0
- Checking the content of the pointer
- 可配置多功能门 SN74LVC1G57, 1G58, 1G97, 1G98, 1G99
- 关于MySql entity framework 6 执行like查询问题解决方案
- MySQL在线备份与恢复工具 -->; Xtrabackup
- WPF combobox 圆角制作
- iOS: TableView如何刷新指定的cell 或section
- Log4net 日志记录配置信息
- javascript 三种弹出对话框
- 使用原生php爬取图片并保存到本地
- 前端面试之Javascript
- ecmall 如何新增挂件
- 解决Myeclipse ctrl+h带来的困扰
- 恺撒密码 I Python实现
- 15. DML, DDL, LOGON 触发器
- [leetcode]253. Meeting Rooms II 会议室II
- 某个php爬虫程序分析--来自wooyun
- Learning Phrase Representations using RNN Encoder–Decoder for Statistical Machine Translation