• 使用工厂bean和Utility Schema定义集合


    工厂bean是实现了beanFactory接口的bean,也可以继承AbstractFactoryBean,主要是用于在给定属性参数之后自动创建一个bean对象。

    我们在使用基本集合标记定义集合时,不能够指定集合的实体类,例如LinkedList、TreeSet或TreeMap等,而且也不能通过将集合定义为可供其他bean引用的单独bean在不同放入bean中共享集合。

    Spring提供了两种选项来提供基本集合标记的不足。

      选项之一使用对应的集合工厂bean:ListFactoryBean、SetFactoryBean、MapFactoryBean。

    <bean id="set" class="org.springframework.beans.factory.config.SetFactoryBean">
          <property name="targetSetClass">
                  <value>java.util.TreeSet</value>
          </property>
          <property  name="sourceSet">
                  <set>
                       <value></value>
                  </set>
          </property>
    </bean>        

      选项二在Spring 2.x之后引入了util schema中使用了集合标记:<util:list>、<util:set>、<util:map>

    xmlns:util="http://www.springframework.org/schema/util"
    xsi:schemalocation="…………
    http://www.springframework.org/schema/util
    http://www.springframework.org/schema/util/spring-util-3.0.xsd"
    
    <util:set  id="" set-class="java.util.TreeSet">
             <value></value>
    </util:set>
  • 相关阅读:
    [CISCN2019 华北赛区 Day1 Web2]ikun
    [BJDCTF 2nd]简单注入
    [BJDCTF2020]ZJCTF,不过如此
    [BJDCTF2020]The mystery of ip
    [SWPU2019]Web1
    [WesternCTF2018]shrine
    [BJDCTF 2nd]假猪套天下第一
    [BJDCTF2020]Mark loves cat
    [GWCTF 2019]我有一个数据库
    C语言学习笔记_函数与函数库
  • 原文地址:https://www.cnblogs.com/lvxiaowei/p/4264648.html
Copyright © 2020-2023  润新知