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

前端之家收集整理的这篇文章主要介绍了spring 通过编程来获取属性文件前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

配置可以读取属性

="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:/<a href="/tag/Meta/" target="_blank" class="keywords">Meta</a>-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:/<a href="/tag/Meta/" target="_blank" class="keywords">Meta</a>-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:/<a href="/tag/Meta/" target="_blank" class="keywords">Meta</a>-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

猜你在找的Spring相关文章