1、前言

众所周知、java中不只有八大简单类型、还有一些集合类型、本文围绕集合类型的注入做一个总结。


2、项目骨架


3、过程

1、创建实体类AllCollectionType

package com.feng.entity;

import java.util.*;

public class AllCollectionType {
private List<String> listElement;
private String[] arrayElement;
private Set<String> setElement;
private Map<String,String> mapElement;
private Properties propsElement; @Override
public String toString() {
return "AllCollectionType{" +
"listElement=" + listElement +
", arrayElement=" + Arrays.toString(arrayElement) +
", setElement=" + setElement +
", mapElement=" + mapElement +
", propsElement=" + propsElement +
'}';
} public List<String> getListElement() {
return listElement;
} public void setListElement(List<String> listElement) {
this.listElement = listElement;
} public String[] getArrayElement() {
return arrayElement;
} public void setArrayElement(String[] arrayElement) {
this.arrayElement = arrayElement;
} public Set<String> getSetElement() {
return setElement;
} public void setSetElement(Set<String> setElement) {
this.setElement = setElement;
} public Map<String, String> getMapElement() {
return mapElement;
} public void setMapElement(Map<String, String> mapElement) {
this.mapElement = mapElement;
} public Properties getPropsElement() {
return propsElement;
} public void setPropsElement(Properties propsElement) {
this.propsElement = propsElement;
}
}

2、配置applicationContext.xml

<?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="collectionDemo" class="com.feng.entity.AllCollectionType">
<property name="listElement">
<list>
<value>足球</value>
<value>蓝球</value>
<value>乒乓球</value>
</list>
</property>
<property name="arrayElement">
<array>
<value>足球1</value>
<value>蓝球1</value>
<value>乒乓球1</value>
</array>
</property>
<property name="setElement">
<set>
<value>足球2</value>
<value>蓝球2</value>
<value>乒乓球2</value>
</set>
</property>
<property name="mapElement">
<map>
<entry>
<key>
<value>foot3</value>
</key>
<value>足球3</value>
</entry>
<entry>
<key>
<value>basket3</value>
</key>
<value>蓝球3</value>
</entry>
<entry>
<key>
<value>pp3</value>
</key>
<value>乒乓球3</value>
</entry>
</map>
</property>
<property name="propsElement">
<props>
<prop key="foot4">足球4</prop>
<prop key="basket4">蓝球4</prop>
<prop key="pp4">乒乓球4</prop>
</props>
</property>
</bean>
</beans>

3、编写测试类

package com.feng.test;

import com.feng.entity.AllCollectionType;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext; public class Test { public static void collectionDemo() {
ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
AllCollectionType type = (AllCollectionType)context.getBean("collectionDemo");
System.out.println(type);
}
public static void main(String[] args) {
collectionDemo();
}
}

4、运行结果

4、总结

本文简单讲述了四种集合属性的注入方式、对之前的注入方式进行了一次补充。

Spring学习(三)几种集合属性的注入方式的更多相关文章

  1. day38 14-Spring的Bean的属性的注入:集合属性的注入

    集合:List.Set.Map. package cn.itcast.spring3.demo6; import java.util.List; import java.util.Map; impor ...

  2. 【Spring学习笔记-MVC-4】SpringMVC返回Json数据-方式2

    <Spring学习笔记-MVC>系列文章,讲解返回json数据的文章共有3篇,分别为: [Spring学习笔记-MVC-3]SpringMVC返回Json数据-方式1:http://www ...

  3. 【Spring学习笔记-MVC-3】SpringMVC返回Json数据-方式1

    <Spring学习笔记-MVC>系列文章,讲解返回json数据的文章共有3篇,分别为: [Spring学习笔记-MVC-3]SpringMVC返回Json数据-方式1:http://www ...

  4. Spring学习(三)--高级装配

    一.Spring profile 在开发软件的时候,有一个很大的挑战就是将应用程序从一个环境迁 移到另外一个环境.开发阶段中,某些环境相关做法可能并不适合迁 移到生产环境中,甚至即便迁移过去也无法正常 ...

  5. Spring学习(三)

    DI (Dependency Injection) 1.依赖注入,组件之间的依赖关系由容器在运行期间决定.Ioc容器注入应用程序某个对象,它所需要的外部资源(包括对象,资源,常量数据). birthd ...

  6. Spring4学习笔记2-配置集合属性

    1 可使用<list> <map> <set>等来配置集合属性 2 List <!-- 配置List属性 --> <bean id="p ...

  7. Spring学习笔记--自动装配Bean属性

    Spring提供了四种类型的自动装配策略: byName – 把与Bean的属性具有相同名字(或者ID)的其他Bean自动装配到Bean的对应属性中. byType – 把与Bean的属性具有相同类型 ...

  8. Spring学习三----------注入方式

    © 版权声明:本文为博主原创文章,转载请注明出处 Spring注入方式 本篇博客只讲最常用的两种注入方式:设值注入和构造器注入.代码为完整代码,复制即可使用. 1.目录结构 2.pom.xml < ...

  9. spring学习三:Spring的Aop、代理

    ref:https://mp.weixin.qq.com/s/J77asUvw8FcnF-6YlX6AAw AOP相关术语:    Joinpoint(连接点):类里面可以被增强的方法,这些方法称为连 ...

随机推荐

  1. Codeforces 1208F - Bits And Pieces(高维前缀和)

    题面传送门 题意:求 \(\max\limits_{i<j<k}a_i|(a_j\&a_k)\). \(1\leq n \leq 10^6,1\leq a_i\leq 2\time ...

  2. Codeforces 1413F - Roads and Ramen(树的直径+找性质)

    Codeforces 题目传送门 & 洛谷题目传送门 其实是一道还算一般的题罢--大概是最近刷长链剖分,被某道长链剖分与直径结合的题爆踩之后就点开了这题. 本题的难点就在于看出一个性质:最长路 ...

  3. 如何使用scp在Linux服务器的后台传输文件?

    目录 一.上传 常规操作 建议 后台运行 二.下载 两台服务器间文件如何传输?对于小文件,可以先从Linux服务器传到window,再传到另一台服务器.对于大的文件,如测序数据.比对文件等.这样的方法 ...

  4. 解决install_github安装R包时无法打开(cannot open)URL?

    最近安装github上的R包,经常显示Error in utils::download.file(url, path, method = method, quiet = quiet, : 无法打开UR ...

  5. 关于蓝牙Mesh您必须知道的七件事

    蓝牙技术联盟于7月19日正式宣布,蓝牙(Bluetooth)技术开始全面支持Mesh网状网络.全新的Mesh功能提供设备间多对多传输,并特别提高构建大范围网络覆盖的通信能力,适用于楼宇自动化.无线传感 ...

  6. Identity Server 4 从入门到落地(五)—— 使用Ajax访问Web Api

    前面的部分: Identity Server 4 从入门到落地(一)-- 从IdentityServer4.Admin开始 Identity Server 4 从入门到落地(二)-- 理解授权码模式 ...

  7. linux 内存变量的分布

    我们知道,linux通过虚拟内存管理进程的内存(进程的地址空间),而进程的地址空间分布如下 : 从进程的空间中可以看出,内存中的变量有的来自可执行elf文件,在elf文件中已经分配好存储空间,有的是在 ...

  8. 【STM32】使用SDIO进行SD卡读写,包含文件管理FatFs(八)-认识内存管理

    [STM32]使用SDIO进行SD卡读写,包含文件管理FatFs(一)-初步认识SD卡 [STM32]使用SDIO进行SD卡读写,包含文件管理FatFs(二)-了解SD总线,命令的相关介绍 [STM3 ...

  9. 关系型数据库和非关系型数据库区别、oracle与mysql的区别

    一.关系型数据库 关系型数据库,是指采用了关系模型来组织数据的数据库.    关系模型是在1970年由IBM的研究员E.F.Codd博士首先提出的,在之后的几十年中,关系模型的概念得到了充分的发展并逐 ...

  10. 【Linux】【Shell】【Basic】字符串操作

    1. 字符串切片:             ${var:offset:number}                 取字符串的子串:                 取字符趾的最右侧的几个字符:${ ...