<context:property-placeholder loading from the filesystem

瘦欲@ 提交于 2020-01-14 00:30:56

问题


<context:property-placeholder ignore-unresolvable="true" location="classpath:test.properties" />

Above mentioned way of loading the property files from contex:property-placeholder works just fine. What I want to do is loading the property file from the file system.

Let's say I have the file in C drive C:\spring\test.properties. Here how can I load the file using context:property-placeholder.


回答1:


Use a file: URL instead of a classpath: one

<context:property-placeholder ignore-unresolvable="true"
     location="file:/C:/spring/test.properties" />



回答2:


Give properties to web application(Spring based) from filesystem(External Location)

1) specify placeholder in applications root xml as

2)define enviornment name as "config" in server's context.xml and give path of file

spring.xml

file:#{contextJndi.lookup('java:comp/env/config')}

context.xml

Environment name="config" override="false" type="java.lang.String" value="D:\config.properties"/>



来源:https://stackoverflow.com/questions/17303261/contextproperty-placeholder-loading-from-the-filesystem

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!