数组注入

public class MyCollection {
     private  String[]array;
     private List<String>list;
     private Set<String>set;
     Map<String,String>map;
     Properties properties;
    public String[] getArray() {
        return array;
    }
    public void setArray(String[] array) {
        this.array = array;
    }
    public List<String> getList() {
        return list;
    }
    public void setList(List<String> list) {
        this.list = list;
    }
    public Set<String> getSet() {
        return set;
    }
    public void setSet(Set<String> set) {
        this.set = set;
    }
    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;
    }
}

<!--数组注入-->
 <bean id="array" class="cn.happy.spring03xmldi.MyCollection">
     <property name="array">
         <array>
             <value>q</value>
             <value>w</value>
             <value>e</value>
             <value>r</value>
         </array>
     </property>
 </bean>

测试

//数值注入
public void test02(){
     ApplicationContext ct= new ClassPathXmlApplicationContext("applicationContextspring03xmldl.xml");
 MyCollection collection=(MyCollection)ct.getBean("array");
 System.out.println(collection.getArray()[1]);

//map双列集合

<!-- map 双列集合-->
<bean id="map" class="cn.happy.spring03xmldi.MyCollection">
<property name="map">
    <map>
        <!-- map中的每一项entry=key+value  -->
        <entry key="1" value="11"></entry>
        <entry key="2" value="22"></entry>
        <entry key="3">
            <value>33</value>
        </entry>
    </map>
</property>
</bean>

测试

public void test02(){
ApplicationContext ct= new ClassPathXmlApplicationContext("applicationContextspring03xmldl.xml");
 MyCollection collection=(MyCollection)ct.getBean("map");
 System.out.println(collection.getMap());
}

结果:

spring数组注入的更多相关文章

  1. Spring 依赖注入优化

    Spring 依赖注入优化 原创: carl.zhao SpringForAll社区 今天 Spring 最大的好处就是依赖注入,关于什么是依赖注入,在Stack Overflow上面有一个问题,如何 ...

  2. Spring 属性注入(二)BeanWrapper 结构

    Spring 属性注入(二)BeanWrapper 结构 Spring 系列目录(https://www.cnblogs.com/binarylei/p/10117436.html) BeanWrap ...

  3. Spring 属性注入(三)AbstractNestablePropertyAccessor

    Spring 属性注入(三)AbstractNestablePropertyAccessor Spring 系列目录(https://www.cnblogs.com/binarylei/p/10117 ...

  4. 浅谈spring依赖注入

    了解依赖注入 前言 先了解下控制反转--转自知乎的国哥 如果一个类A 的功能实现需要借助于类B,那么就称类B是类A的依赖,如果在类A的内部去实例化类B,那么两者之间会出现较高的耦合,一旦类B出现了问题 ...

  5. java后端开发三年!你还不了解Spring 依赖注入,凭什么给你涨薪

    前言 前两天和一个同学吃饭的时候同学跟我说了一件事,说他公司有个做了两年的人向他提出要涨薪资,他就顺口问了一个问题关于spring依赖注入的,那个要求涨薪的同学居然被问懵了...事后回家想了想这一块确 ...

  6. Spring自动注入properties文件

    实现spring 自动注入属性文件中的key-value. 1.在applicationContext.xml配置文件中,引入<util />命名空间. xmlns:util=" ...

  7. spring 属性注入

    Spring的核心技术室依赖注入,下面是依赖注入之属性注入的实现过程,牛刀小试,请看效果. 1.首先添加Spring.Web引用.本例中是使用分层思想来演示的,下面是项目的结构和UserModel类的 ...

  8. spring 多线程 注入 服务层 问题

    在用多线程的时候,里面要用到Spring注入服务层,或者是逻辑层的时候,一般是注入不进去的.具体原因应该是线程启动时没有用到Spring实例不池.所以注入的变量值都为null. 详细:http://h ...

  9. Spring 依赖注入方式详解

    平常的Java开发中,程序员在某个类中需要依赖其它类的方法. 通常是new一个依赖类再调用类实例的方法,这种开发存在的问题是new的类实例不好统一管理. Spring提出了依赖注入的思想,即依赖类不由 ...

随机推荐

  1. React 特别需要注意的地方

    如图:

  2. Spring整合JUnit4测试时,使用注解引入多个配置文件

    转自:https://blog.csdn.net/pwh309315228/article/details/62226372 一般情况下: @ContextConfiguration(Location ...

  3. map-reduce的八个流程

    下面讲解这八个流程  Inputformat-->map-->(combine)-->partition-->copy&merge-->sort-->red ...

  4. macos下清除dnscache

    sudo killall -HUP mDNSResponder 参见链接

  5. 5. Python大法之告别脚本小子--各类URL采集器编写

    在i春秋上面,有很多不错的脚本: https://bbs.ichunqiu.com/forum.php?mod=collection&action=view&ctid=137 http ...

  6. 介绍一款“对话框”组件之 “artDialog”在项目中的使用

    在实际开发项目中经常会用到对话框组件,提示一些信息.其实有很多,例如:在项目中常用到的“Jquery-UI.Jquery-EasyUI”的.Dialog,他们也很强大,Api文档也很多.今天就介绍一款 ...

  7. Library学习日志(……)

    添加Library在buildpath中,就是右键工程->properties->java buildpath->Libraries 然后点击add Library就是添加Libra ...

  8. Java Script 学习笔记 -- Ajax

    AJAX 一 AJAX预备知识:json进阶 1.1 什么是JSON? JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式.JSON是用字符串来表示Javas ...

  9. CODING 告诉你硅谷的研发项目管理之道(4)

    写在前面 优秀的项目管理者是怎么工作的,如何帮助研发团队高效工作?一直是 CODING 关注的重要话题,我们不断地打磨 CODING 研发系统来让开发更简单.近期我们精心挑选了几篇硅谷科技公司研发管理 ...

  10. 空字符串‘’ null false 区别

    1.''空字符串 .null 和false都是以值为0来存储的   只是数据结构不一致而已 空字符串------字符串数据格式 null -----------null数据格式 false ----- ...