首页 > 编程语言 > 详细

spring 通过编程来获取属性文件

时间:2015-10-08 19:52:39      阅读:137      评论:0      收藏:0      [点我收藏+]

配置可以读取属性:

<beans profile="dev">
        <context:property-placeholder ignore-resource-not-found="true"
                                      location="classpath:/META-INF/config/dev/*.properties" />
    </beans>

    <beans profile="idc">
        <context:property-placeholder ignore-resource-not-found="true"
                                      location="classpath:/META-INF/config/idc/*.properties" />
    </beans>

    <beans profile="production">
        <context:property-placeholder ignore-resource-not-found="true"
                                      location="classpath:/META-INF/config/prod/*.properties" />
    </beans>

    <beans profile="test">
        <context:property-placeholder ignore-resource-not-found="true"
                                      location="classpath:/META-INF/config/test/*.properties" />
    </beans>

 

也可以通过编程的形式获取文件属性:

Resource resource = new ClassPathResource("/my.properties");
Properties props = PropertiesLoaderUtils.loadProperties(resource);

参考文献:

【1】http://stackoverflow.com/questions/1771166/access-properties-file-programatically-with-spring

 

spring 通过编程来获取属性文件

原文:http://www.cnblogs.com/davidwang456/p/4861855.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!