新建一个bean,设置相应的集合属性

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
public class Collections {
    private Set<String> sets;
    private List<String> lists;
    private Map<String,String> maps;
    public Set<String> getSets() {
        return sets;
    }
    public void setSets(Set<String> sets) {
        this.sets = sets;
    }
    public List<String> getLists() {
        return lists;
    }
    public void setLists(List<String> lists) {
        this.lists = lists;
    }
    public Map<String, String> getMaps() {
        return maps;
    }
    public void setMaps(Map<String, String> maps) {
        this.maps = maps;
    }
}

在配置文件中配置:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<bean id="coll" class=" com.fz.entity.Collections">
    <property name="sets">
        <set>
            <value>set1</value>
            <value>set2</value>
        </set>
    </property>
    <property name="lists">
        <list>
            <value>list1</value>
            <value>list2</value>
        </list>
    </property>
    <property name="maps">
        <map>
            <entry key="map1" value="map1" />
            <entry key="map2" value="map2" />
            <entry key="map3" value="map3" />
        </map>
    </property>
</bean>

测试获取bean的值,此时控制台打印:list1 和list2

1
2
3
4
5
6
7
8
@Test
public void getProperties(){
    ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
    Collections coll = (Collections) ctx.getBean("coll");
    for (String temp : coll.getLists()) {
        System.out.println(temp);
    }
}

SpringXML方式配置bean的集合注入:list,map,properties的更多相关文章

  1. SpringXML方式配置bean的生存范围Scope

    在一个bean的配置里面可以指定一个属性Scope,也就是bean的范围,bean的生命周期. Scope可取的值5种:singleton(默认).prototype.request.session. ...

  2. SpringXML方式配置bean的自动装配autowire

    Spring的自动装配,也就是定义bean的时候让spring自动帮你匹配到所需的bean,而不需要我们自己指定了. 例如: User实体类里面有一个属性role 1 2 3 4 5 6 7 publ ...

  3. SpringXML方式配置bean的生命周期lifecycle

    在Spring中容器在初始化某个bean的时候会有相应的生命周期,类似于Servlet,有相应的init,destory等方法 例如:如下service 1 2 3 4 5 6 7 8 9 10 11 ...

  4. SpringXML方式配置bean的懒加载lazy-init

    lazy-init(懒加载),表示该bean在容器初始化的时候不进行初始化. 例如: <bean name="role1" class="com.fz.entity ...

  5. 跟着刚哥学习Spring框架--通过XML方式配置Bean(三)

    Spring配置Bean有两种形式(XML和注解) 今天我们学习通过XML方式配置Bean 1. Bean的配置方式 通过全类名(反射)的方式   √ id:标识容器中的bean.id唯一. √ cl ...

  6. spring学习笔记 星球日two - 注解方式配置bean

    注解要放在要注解的对象的上方 @Autowired private Category category; <?xml version="1.0" encoding=" ...

  7. spring学习笔记 星球日one - xml方式配置bean

    ide: idea lib包的导入:http://webcache.googleusercontent.com/search?q=cache:http://zyjustin9.iteye.com/bl ...

  8. Spring框架学习(6)使用ioc注解方式配置bean

    内容源自:使用ioc注解方式配置bean context层 : 上下文环境/容器环境 applicationContext.xml 1 ioc注解功能 注解 简化xml文件配置 如 hibernate ...

  9. 跟着刚哥学习Spring框架--通过注解方式配置Bean(四)

    组件扫描:Spring能够从classpath下自动扫描,侦测和实例化具有特定注解的组件. 特定组件包括: 1.@Component:基本注解,识别一个受Spring管理的组件 2.@Resposit ...

随机推荐

  1. 基于session和token的身份认证方案

    一.基于session的身份认证方案 1.方案图示 2.比较通用的鉴权流程实现如下: 在整个流程中有两个拦截器. 第一个拦截器AuthInteceptor是为了每一次的请求的时候都先去session中 ...

  2. Linux远程管理器xshell和xftp使用教程,以及遇到关闭Xshell后项目也停止的解决方法

    1.xshell 是一个强大的安全终端模拟软件,它支持SSH1, SSH2, 以及Microsoft Windows 平台的TELNET 协议. 2.是一个基于 MS windows 平台的功能强大的 ...

  3. 有关string stringbuff stringbuild 的区别

    string  stringbuff stringbuild的执行效率: stringbuild>stringbuff>string String类是不可变类,任何对String的改变都会 ...

  4. 机器学习与R语言:C5.0

    #---------------------------------------- # 功能描述:演示C50建模过程 # 数据集:汉堡大学信贷模型,信贷数据 # #------------------ ...

  5. 枚举转SelectList扩展方法

        public enum Avbc    {        Red=1,        Blue=2,        Whilt=3,        Black=4    } public st ...

  6. cl.exe 命令行编译sqlite3 sqlite3.dll及sqlite3.exe

    有点被宇宙最强的ide惯坏了,封装的太好,不能像gcc那样一步步了解其原理,其实强大的vs背后也有类似gcc的cl.exe 看到How To Compile SQLite http://sqlite. ...

  7. IDEA 安装mybatis 插件 可以通过mapper定位到xml

    在使用IDEA的时候 ,通过mapper类定位到 xml文件是让人很头疼的问题! 无意中发现了这个插件!可以通过类方法直接定位到xml中!比较强大!哈哈! 这玩意好像是付费的! 不过不破解也能用! 哈 ...

  8. zsh + oh-my-zsh 主题预览

    The Themes robbyrussell the (default) that Robby uses The rest of the themes, in alphabetical order: ...

  9. Spring @Scheduler使用cron时的执行问题

    主要想弄清使用Spring @Scheduler cron表达式时的两个问题: 同一定时任务,第二次触发时间到了,第一次还没有执行完成时会执行吗? 不同的定时任务,相互之间是否有影响? 结论写在前面: ...

  10. RunLoop Note

    I. Begin from Apple Document Apple describes the priciples of runloop in Threading Programming Guide ...