问题
<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