2

我正在尝试将 PropertyPlaceholderConfigurer 与外部属性文件一起使用,该文件不是 WAR 文件的一部分。

我将bean配置如下:

<property name="location" value="${jboss.server.data.dir}/my-dir/common.properties"/>

部署 WAR 文件时,我收到一条错误消息:

.....无法加载属性;嵌套异常是 java.io.FileNotFoundException: 无法打开 ServletContext 资源 [/C:/dir/jboss-as-7.1.1.Test/standalone/data/my-dir/common.properties]

有什么办法可以将属性文件放在 WAR 文件之外?

4

1 回答 1

4

是的,您可以,但使用值 classpath:common.properties。只要确保它在某个地方的类路径中。

<property name="location" value="classpath:common.properties"/>

如果文件不在类路径中,您也可以使用文件:来使其正常工作。

<property name="location" value="file:${jboss.server.data.dir}/my-dir/common.properties"/>
于 2013-01-11T22:08:25.520 回答