代码示例如下:

创建BeanClass实体类

public class BeanClass {
private String[] arrs;//数组类型
private List<String> list;//List集合类型
private Set<String> set;//Set集合类型
private Map<String,Integer> map;//Map集合类型
private Properties prop;//属性类型 //getter和setter方法
//toString()方法 }

在applicationContext.xml中配置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"> <!--集合类型属性注入-->
<bean id="beanClass" class="entity.BeanClass">
<!--数组类型-->
<property name="arrs">
<list>
<value>aa</value>
<value>bb</value>
</list>
</property>
<!--List集合-->
<property name="list">
<list>
<value>111</value>
<value>222</value>
</list>
</property>
<!--Set集合-->
<property name="set">
<set>
<value>aaa</value>
<value>bbb</value>
</set>
</property>
<!--Map集合-->
<property name="map">
<map>
<entry key="aa" value="11"></entry>
<entry key="bb" value="22"></entry>
</map>
</property>
<!--Properties属性-->
<property name="prop">
<props>
<prop key="aa">11</prop>
<prop key="bb">22</prop>
</props>
</property>
</bean> </beans>

测试代码

@Test
public void demo(){
//初始化Spring容器ApplicationContext,加载配置文件
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
//通过容器获取实例
BeanClass beanClass = (BeanClass) ctx.getBean("beanClass");
System.out.println(beanClass);
}

运行结果

Spring框架学习04——复杂类型的属性注入的更多相关文章

  1. Spring框架学习一

    Spring框架学习,转自http://blog.csdn.net/lishuangzhe7047/article/details/20740209 Spring框架学习(一) 1.什么是Spring ...

  2. Spring框架学习之IOC(二)

    Spring框架学习之IOC(二) 接着上一篇的内容,下面开始IOC基于注解装配相关的内容 在 classpath 中扫描组件 <context:component-scan> 特定组件包 ...

  3. Spring框架学习之IOC(一)

    Spring框架学习之IOC(一) 先前粗浅地学过Spring框架,但当时忙于考试及后期实习未将其记录,于是趁着最近还有几天的空闲时间,将其稍微整理一下,以备后期查看. Spring相关知识 spri ...

  4. Spring框架学习总结(上)

    目录 1.Spring的概述 2.Spring的入门(IOC) 3.Spring的工厂类 4.Spring的配置 5.Spring的属性注入 6.Spring的分模块开发的配置 @ 1.Spring的 ...

  5. spring框架学习(二)依赖注入

    spring框架为我们提供了三种注入方式,分别是set注入,构造方法注入,接口注入.接口注入不作要求,下面介绍前两种方式. 1,set注入 采用属性的set方法进行初始化,就成为set注入. 1)给普 ...

  6. Spring框架学习(二)

    一.依赖注入的三种注入方式 Spring框架为我们提供了三种注入方式:set注入.构造方法注入和接口注入. 1.set注入 规律:无论给什么赋值,配置文件中<property>标签的nam ...

  7. Spring框架学习1

    AnonymouL 兴之所至,心之所安;尽其在我,顺其自然 新随笔 管理   Spring框架学习(一)   阅读目录 一. spring概述 核心容器: Spring 上下文: Spring AOP ...

  8. (转)Spring如何装配各种集合类型的属性

    http://blog.csdn.net/yerenyuan_pku/article/details/52858499 在前面我们已经会注入基本类型对象和其他bean,现在我们就来学习如何注入各种集合 ...

  9. Spring框架学习笔记(5)——Spring Boot创建与使用

    Spring Boot可以更为方便地搭建一个Web系统,之后服务器上部署也较为方便 创建Spring boot项目 1. 使用IDEA创建项目 2. 修改groupid和artifact 3. 一路n ...

随机推荐

  1. Freemarker list 的简单使用

    freemarker list (长度,遍历,下标,嵌套,排序) 1. freemarker获取list的size : Java ArrayList<String> list = new ...

  2. Linux安装后首次设置root密码

    ① 1.sudo password root //给指定用户设置密码 2.sudo passwd root //给指定用户设置密码 ②su root //切换到指定用户

  3. SpringBoot集成Dubbo

    (1).新建一个普通Maven项目,用于存放一些公共服务接口及公共的Bean等. 项目: 公共Bean: package cn.coreqi.entities; import java.io.Seri ...

  4. Difference between plt.draw() and plt.show() in matplotlib

    Difference between plt.draw() and plt.show() in matplotlib down voteaccepted plt.show() will display ...

  5. UML和模式应用4:初始阶段(2)--需求科目之进化式需求

    1. 前言 UP开发包括四个阶段:初始阶段.细化阶段.构建阶段.移交阶段: UP每个阶段包括 业务建模.需求.设计等科目: 需求是UP科目之一,在初始阶段需求科目的工作量占据较大的部分.但是初始阶段的 ...

  6. S5PV210初始化系统时钟

    S5PV210初始化系统时钟 S5PV210时钟体系S5PV210中包含3大类时钟domain,分别是主系统时钟domain (简称MSYS,下面将使用简称来进行相关讲解).显示相关的时钟domain ...

  7. python装饰器@用法

    这个是我见过比较好的讲解链接: [廖雪峰的官方网站 - 装饰器]

  8. Linear Algebra(未完待续)

    [矩阵消元] The result of multiplying a matrix by some vector is a combination of the columns of the matr ...

  9. python 全栈开发,Day36(作业讲解(大文件下载以及进度条展示),socket的更多方法介绍,验证客户端链接的合法性hmac,socketserver)

     先来回顾一下昨天的内容 黏包现象粘包现象的成因 : tcp协议的特点 面向流的 为了保证可靠传输 所以有很多优化的机制 无边界 所有在连接建立的基础上传递的数据之间没有界限 收发消息很有可能不完全相 ...

  10. python 全栈开发,Day7(元组转换,列表以及字典的坑,集合,关系测试,深浅copy,编码补充)

    一.元组转换 数字 tu = (1) tu1 = (1,) print(tu,type(tu)) print(tu1,type(tu1)) 执行输出: 1 <class 'int'>(1, ...