spring 装配集合
1:创建pojo,属性包含集合,集合元素为基本类型
package com.liyafei.pojo; import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set; public class ComplexAssemble { private Long id;
private List<String> list;
private Map<String,String> map;
private Properties properties;
private Set<String> set;
private String[] array;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public List<String> getList() {
return list;
}
public void setList(List<String> list) {
this.list = list;
}
public Map<String, String> getMap() {
return map;
}
public void setMap(Map<String, String> map) {
this.map = map;
}
public Properties getProperties() {
return properties;
}
public void setProperties(Properties properties) {
this.properties = properties;
}
public Set<String> getSet() {
return set;
}
public void setSet(Set<String> set) {
this.set = set;
}
public String[] getArray() {
return array;
}
public void setArray(String[] array) {
this.array = array;
}
}
package com.liyafei.pojo; import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set; public class ComplexAssemble { private Long id;
private List<String> list;
private Map<String,String> map;
private Properties properties;
private Set<String> set;
private String[] array; setter and getter
}
2:装配bean
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
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-4.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.0.xsd"> <bean id="complexAssembly" class="com.liyafei.pojo.ComplexAssemble">
<property name="id" value="1" />
<property name="list">
<list>
<value>value-list-1</value>
<value>value-list-2</value>
<value>value-list-3</value>
</list>
</property>
<property name="map">
<map>
<entry key="key1" value="value-key-1"/>
<entry key="key2" value="value-key-2"/>
<entry key="key3" value="value-key-3"/>
</map>
</property>
<property name="properties">
<props>
<prop key="prop1">value-prop-1</prop>
<prop key="prop2">value-prop-2</prop>
<prop key="prop3">value-prop-3</prop>
</props>
</property>
<property name="set">
<set>
<value>value-set-1</value>
<value>value-set-2</value>
<value>value-set-3</value>
</set>
</property>
<property name="array">
<array>
<value>value-array-1</value>
<value>value-array-2</value>
<value>value-array-3</value>
</array>
</property>
</bean>
</beans>
3:创建pojo,属性包含集合,集合元素为对象类型
public class Role {
private Long id;
private String roleName;
private String note;
public Role(){
}
public Role(Long id, String roleName, String note) {
this.id = id;
this.roleName = roleName;
this.note = note;
}
setter and getter
}
public class User {
private Long id;
private String userName;
setter and getter
}
装配类:
public class UserRoleAssembly {
private Long id;
private List<Role> list;
private Map<Role, User> map;
private Set<Role> set;
setter and getter
}
4:装备bean
<bean id="role1" class="com.liyafei.pojo.Role">
<property name="id" value="1"></property>
<property name="roleName" value="role_name_1"></property>
<property name="note" value="role_note_1"></property>
</bean>
<bean id="role2" class="com.liyafei.pojo.Role">
<property name="id" value="2"></property>
<property name="roleName" value="role_name_2"></property>
<property name="note" value="role_note_2"></property>
</bean>
<bean id="user1" class="com.liyafei.pojo.User">
<property name="id" value="1"></property>
<property name="userName" value="user_name_1"></property>
<property name="note" value="role_note_1"></property>
</bean>
<bean id="user2" class="com.liyafei.pojo.User">
<property name="id" value="2"></property>
<property name="userName" value="user_name_2"></property>
<property name="note" value="role_note_2"></property>
</bean> <bean id="userRoleAssembly" class="com.liyafei.pojo.UserRoleAssemply">
<property name="id" value="1"></property>
<property name="list">
<list>
<ref bean="role1"/>
<ref bean="role2"/>
</list>
</property>
<property name="map">
<map>
<entry key-ref="role1" value-ref="user1"></entry>
<entry key-ref="role2" value-ref="user2"></entry>
</map>
</property>
<property name="set">
<set>
<ref bean="role1"/>
<ref bean="role2"/>
</set>
</property>
</bean>
spring 装配集合的更多相关文章
- spring装配集合
前面我们已经了解了怎样使用spring装备简单的属性(使用value属性)和引用其它bean的属性(使用ref属性).可是value和ref仅在Bean的属性值是单个值的情况下才实用.当bean的属性 ...
- Spring 装配Bean
Spring 装配Bean 装配解释: 创建应用对象之间协作关系的的行为通常称为装配(wiring),这也是依赖注入的本质 依赖注入是Spring的基础要素 一 : 使用spring装配Bean基础介 ...
- Spring装配Bean---使用xml配置
声明Bean Spring配置文件的根元素是<beans>. 在<beans>元素内,你可以放所有的Spring配置信息,包括<bean>元素的声明. 除了Bean ...
- Spring装配bean
Spring配置的可选方案 Spring提供了如下三种装配机制: (1)在XML中显式配置 (2)在Java中显式配置 (3)隐式的bean发现机制和自动装配 Spring有多种方式可以装配bean, ...
- Spring装配Bean之XML装配bean
在Spring刚出现的时候,XML是描述配置的主要方式,在Spring的名义下,我们创建了无数行XML代码.在一定程度上,Spring成为了XML的同义词. 现在随着强大的自动化配置和Java代码的配 ...
- Spring 装配Bean入门级
装配解释: 创建应用对象之间协作关系的的行为通常称为装配(wiring),这也是依赖注入的本质 依赖注入是Spring的基础要素 一 : 使用spring装配Bean基础介绍 1 :声明Bean B ...
- spring装配---处理自动装配的歧义性
一.歧义性 当我们使用spring的注解进行自动装配bean时,如果不仅有一个bean能够匹配结果的话,会抛出NoUniqueBeanDefinitionException: 例如本例中 当sprin ...
- JAVA入门[13]-Spring装配Bean
一.概要 Sping装配bean主要有三种装配机制: 在XML中进行显式配置. 在Java中进行显式配置. 隐式的bean发现机制和自动装配. 原则: 建议尽可能地使用自动配置的机制,显式配置越少越好 ...
- spring/java ---->记录和整理用过的注解以及spring装配bean方式
spring注解 @Scope:该注解全限定名称是:org.springframework.context.annotation.Scope.@Scope指定Spring容器如何创建Bean的实例,S ...
随机推荐
- Centos6下Python3的编译安装
本文转载自 Centos6下Python3的编译安装 系统环境:CentOS 6.8-Minimal 安装Python依赖包: 1 [root@Python src]# yum install zli ...
- 深入理解 Neutron -- OpenStack 网络实现(2):VLAN 模式
问题导读 1.br-int.br-ethx的作用是什么?2.安全组策略是如何实现的?3.VLAN 模式与GRE模式有哪些不同点?流量上有哪些不同?4.L3 agent实现了什么功能? 接上篇深入理解 ...
- MFC控件CTabCtrl关联变量
1.先建立一个对话框MFC应用程序,然后在工具箱里面把Tab Control控件放到对话框中的合适位置上. 再在对话框类中,将该控件绑定一个变量 用两种方法: 1 ) 自己定义成员变量 CTabCtr ...
- Elasticsearch 学习之 Marvel概念
概要 含义如下: 搜索速率:对于单个索引,它是每秒查找次数*分片数.对于多个索引,它是每个索引的搜索速率的总和. 搜索延迟:每个分片中的平均延迟. 索引速率:对于单个索引,它是每秒索引的数量*分片数量 ...
- filter对数组和对象的过滤
1,对数组的过滤 let arr = ['1', '2', '3'] let b = arr.filter(val => val === '2') console.log(b) // ['2] ...
- How to Use Postman to Manage and Execute Your APIs
How to Use Postman to Manage and Execute Your APIs Postman is convenient for executing APIs because ...
- 你可能不知道的shell、bash二三事(Centos 7)
个人.bashrc: ~/.bashrc: # .bashrc # User specific aliases and functions alias rm='rm -i' alias cp='cp ...
- 新浪的动态策略灰度发布系统:ABTestingGateway
原文链接:http://www.open-open.com/lib/view/open1439889185239.html ABTesingGateway 是一个可以动态设置分流策略的灰度发布系统,工 ...
- 【BZOJ5146】有趣的概率 概率+组合数(微积分)
[BZOJ5146]有趣的概率 Description "可爱的妹子就像有理数一样多,但是我们知道的,你在数轴上随便取一个点取到有理数的概率总是0,"芽衣在床上自顾自的说着这句充满 ...
- 在稳定性测试中,将测试结果持续填加进入html报告
公司需要设计一个稳定性测试,就是一直持续的跑不同的用例,直到人为停止,用例基本完成,基本框架思路就是随机选择一个testcase,跑完后输出结果.但存在一个问题,现在的unittest或nose测试报 ...