使用属性占位符文件,我们曾经有过的方式从classpath中的文件加载性能:如何在文件系统
<context:property-placeholder location="classpath:myConfigFile.properties" />
和它的工作很大。但是现在我们想要从不在类路径中的系统上的特定文件加载属性。我们希望能够动态加载文件,因此我们使用Java环境变量来填充文件。我给下面一个简单的例子:
在Java:
System.setProperty("my.prop.file", "/path/to/myConfigFile.properties");
在Spring XML:
<context:property-placeholder location="${my.prop.file}" />
我也尝试过这种方式,由于从卢西亚诺一个想法:
<context:property-placeholder properties-ref="prop" />
<util:properties id="prop" location="reso"/>
<bean id="reso" class="org.springframework.core.io.FileSystemResource">
<constructor-arg index="0" value="${my.prop.file}" />
</bean>
我试过的一切都失败了。不管我设置my.prop.file。最大的点击包括:
<context:property-placeholder location="/path/to/myConfigFile.properties" />
(ClassNotFoundException: .path.to.myConfigFile.properties)
<context:property-placeholder location="file:/path/to/myConfigFile.properties" />
(ClassNotFoundException: file:.path.to.myConfigFile.properties)
<context:property-placeholder location="file:///path/to/myConfigFile.properties" />
(ClassNotFoundException: file:...path.to.myConfigFile.properties)
如何使用属性占位符的位置在文件系统上而不在类路径上?我们使用Spring 3.0.5。
事实证明,运行加载弹簧文件的Java程序的脚本存在问题。感谢您的帮助。我将要求删除这个问题,毕竟原始代码是有效的。 谢谢你的帮助。
BTW强烈不同意瓦特/这个被关闭 –
也不同意这个结论,我在Google搜索后来到了这里,它描述了我的确切问题...... –
我也是 - 我不明白为什么这个关于“过于本地化”的类别关闭了?它看起来相当普遍对我? – monojohnny