Spring属性注入的XML配置
2016-09-01 19:02
253 查看
1、简单bean配置
配置bean的简单属性,基本数据类型和String。
引用其它bean
外部bean
2、装配集合
2.1、装配List和数组
2.2、装配Set
2.3、[b]装配Map[/b]
2.4、装配Properties
配置bean的简单属性,基本数据类型和String。
<bean id="user" class="com.rk.entity.User"> <property name="age"value="60"></property> <propertyname="name" value="RK"></property> </bean>
引用其它bean
外部bean
<bean id="userDao" class="com.rk.dao.UserDaoImpl" /> <bean id="userService" class="com.rk.service.impl.UserServiceImpl"> <!-- 引用类型 --> <property name="userDao" ref="userDao" /> </bean>内部bean
<bean id="userService" class="com.rk.service.impl.UserServiceImpl"> <!-- 内部bean注入 --> <property name="userDao"> <bean class="com.rk.dao.UserDaoImpl" /> </propert> </bean>
2、装配集合
2.1、装配List和数组
<!-- 装配list --> <property name="lists"> <list> <value>list1</value> <value>list2</value> <ref bean="user"/> </list> </property>
<!-- 装配数组 --> <property name="array"> <list> <value>obj1</value> <value>obj2</value> <ref bean="user"/> </list> </property>
2.2、装配Set
<!-- 装配set --> <property name="sets"> <set> <value>set1</value> <value>set2</value> <ref bean="user"/> </set> </property>
2.3、[b]装配Map[/b]
<!-- 装配map--> <property name="maps"> <map> <entry key="key01"> <value>map01</value> </entry> <entry key="key02"> <value>map02</value> </entry> </map> </property>map中的<entry>的数值和<list>以及<set>的一样,可以使任何有效的属性元素,需要注意的是key值必须是String的。
2.4、装配Properties
<!--装配Properties --> <property name="props"> <props> <prop key="key01">prop1</prop> <prop key="key02">prop2</prop> </props> </property>
相关文章推荐
- Spring基于xml配置文件对list、set、map集合的属性注入
- Spring根据XML配置文件 p名称空间注入属性的实例
- Spring代码实例系列-09:通过Spring PropertyPlaceholderConfigurer将properties配置的属性注入到xml配置文件中
- Spring根据XML配置文件注入属性 其实也是造bean,看看是使用constructor还是setter顺带完成属性赋值
- Spring 配置bean, 注解方式配置 xml方式要生产set方法方便属性注入,注解方式不需要,利用反射机制注入
- spring 注入java.util.Properties 属性两种xml中的配置练习
- spring xml 配置 属性注入 构造方法注入
- Spring根据XML配置文件注入对象类型属性
- Spring根据XML配置文件注入属性的方法
- Spring根据XML配置文件 p名称空间注入属性
- Spring 配置文件XML中<beans>中属性概述
- Spring基础之二:xml配置注入
- Spring AOP注解通过@Autowired,@Resource,@Qualifier,@PostConstruct,@PreDestroy注入属性的配置文件详解
- Spring中使用Map、Set、List、数组、属性集合的注入方法配置文件
- Spring ApplicationContext.xml配置的12个技巧和Bean属性说明
- Spring AMQP实例 以及Spring 配置文件动态注入属性使用实战
- Spring AOP注解通过@Autowired,@Resource,@Qualifier,@PostConstruct,@PreDestroy注入属性的配置文件详解
- spring通过注解依赖注入和获取xml配置混合的方式
- spring与jpa整合 简化persistence.xml配置文件 使用属性文件 数据源dbcp访问数据库
- Spring依赖注入 — 集合属性配置