加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

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

发布时间:2020-12-15 01:51:51 所属栏目:大数据 来源:网络整理
导读:配置可以读取属性: ="classpath:/META-INF/config/dev/*.properties" /> beans profile="idc"gt; context:property-placeholder ignore-resource-not-found="true"span style="color: #000000;"gt; location/span="classpath:/META-INF/config/idc/*.proper

配置可以读取属性:

="classpath:/META-INF/config/dev/*.properties" />
<beans profile="idc"&gt;
    <context:property-placeholder ignore-resource-not-found="true"<span style="color: #000000;"&gt;
                                  location</span>="classpath:/META-INF/config/idc/*.properties" />
</beans>

<beans profile="production"&gt;
    <context:property-placeholder ignore-resource-not-found="true"<span style="color: #000000;"&gt;
                                  location</span>="classpath:/META-INF/config/prod/*.properties" />
</beans>

<beans profile="test"&gt;
    <context:property-placeholder ignore-resource-not-found="true"<span style="color: #000000;"&gt;
                                  location</span>="classpath:/META-INF/config/test/*.properties" />
</beans></pre>

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

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

参考文献:

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读