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. 【POJ1845】Sumdiv【算数基本定理 + 逆元】

    描述 Consider two natural numbers A and B. Let S be the sum of all natural divisors of A^B. Determine ...

  2. MySQL 数据库的下载、安装和测试

    实例:Ubuntu 20.04 安装 mysql-server_5.7.31-1ubuntu18.04_amd64.deb-bundle.tar 1. 下载安装MySQL(安装 MySQL 5.7) ...

  3. LeetCode 从头到尾打印链表

    LeetCode 从头到尾打印链表 题目描述 输入一个链表头节点,从尾到头反过来返回每个节点的值(用数组返回). 示例 1: 输入:head = [1,3,2] 输出:[2,3,1] 一得之见(Jav ...

  4. abandon, abbreviation

    abandon 近/反义词: continue, depart, desert (做动词时读作diˈzəːt), discard, give up, quit, surrender搭配: altoge ...

  5. ubuntu18.10搜狗输入法的安装

    记录一下 1.卸载ibus ubuntu默认使用ibus管理输入法,官方推荐使用fcitx.我们先卸载ibus sudo apt-get remove ibus 清除ibus配置,如果没有设置 sud ...

  6. Angular中怎样创建service服务来实现组件之间调用公共方法

    Angular组件之间不能互相调用方法,但是可以通过创建服务来实现公共方法的调用. 实现 创建服务命令 ng g service 服务路径/服务名 比如这里在app/services目录下创建stor ...

  7. c学习 - 第七章:数组

    7.3.6 字符串处理函数 (1).puts(字符数组) 字符串输出到终端 (2).gets(字符数组) 从标准输入获取字符串(包括空格) (3).strcat(字符数组1,字符数组2) 连接两个字符 ...

  8. lvm 创建扩展

    fdisk /dev/sdgnpt8ewpartprobepvcreate /dev/sdg1vgcreate multibank /dev/sdg1lvcreate -l +100%FREE -n ...

  9. Output of C++ Program | Set 16

    Predict the output of following C++ programs. Question 1 1 #include<iostream> 2 using namespac ...

  10. Android 清除本地缓存

    主要功能:清除内.外缓存,清除数据库,清除Sharepreference,清除files和清除自定义目录 public class DataCleanManager { //清除本应用内部缓存(/da ...