代码示例如下:

创建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. SpringMVC跨重定向请求传递数据

    (1)使用URL模板以路径变量和查询参数的形式传递数据(一些简单的数据) @GetMapping("/home/index") public String index(Model ...

  2. 单页应用 WebApp SPA 骨架 框架 路由 页面切换 转场

    这里收录三个同类产品,找到他们花了我不少时间呢. 张鑫旭写的mobilebone自述:mobile移动端,PC桌面端页面无刷新过场JS骨架,简单.专注!http://www.zhangxinxu.co ...

  3. PHP查看编译参数

    PHP查看编译参数 [root@test ~]# php -i|grep configure Configure Command => './configure' '--prefix=/usr/ ...

  4. [转]解决win7 64位操作系统下安装PL/SQL后连接报错问题: make sure you have the 32 bits oracle client installed

    1. 在Oracle官网(http://www.oracle.com/technetwork/topics/winsoft-085727.html)下载文件: instantclient-basic- ...

  5. 『转载』hadoop2.x常用端口、定义方法及默认端口

    『转载』hadoop2.x常用端口.定义方法及默认端口 1.问题导读 DataNode的http服务的端口.ipc服务的端口分别是哪个? NameNode的http服务的端口.ipc服务的端口分别是哪 ...

  6. scn 时间

    Scn转换成时间: select to_char(scn_to_timestamp(3998591352171),'YYYY-MM-DD HH24:MI:SS') from dual: 时间转换成sc ...

  7. android测试点整理

    Android的功能测试点 安装\卸载 App具体功能点 联网(默认的联网方式是什么?Wifi orSim卡? 网络切换是否有相应的提示说明? 飞行模式) 程序进入输入功能时,是否正常弹出键盘;键盘是 ...

  8. 基于Apache的阿里云部署Node.js服务器(Windows环境)

    1 前言 由于nodejs项目对方开放了多个端口,而且阿里云上的Apache服务器(windows)已经挂载了网站,此时需要把此项目也挂上去,网上查询资料,方法略少,基本是基于nginx版本的. 2  ...

  9. Dotfuscator使用

    参考:https://www.cnblogs.com/xiezunxu/articles/7228741.html

  10. PYTHON-文件处理-练习

    ## 一.实现用户注册功能# 思路:# 用户输入用户名.密码# 将用户输入的内容按照固定的格式,比如:egon:123,存入文件# 可以往一个文件中重复注册新的用户名和密码# 附加:# 1.对输入的用 ...