【发布时间】:2015-03-24 11:49:49
【问题描述】:
我想在启动 Jboss 4.2 时读取外部属性文件。我想将它添加到类路径以从 WAR 文件中读取它。我已经看到使用模块的 Jboss 6 的不同解决方案,但我还没有看到任何与 JBoss 4.2 相关的内容。
我在“jboss-service.xml”中包含了以下代码:
<!-- Bean for reading properties -->
<mbean code="org.jboss.varia.property.SystemPropertiesService"
name="jboss.util:type=Service,name=SystemProperties">
<!-- Load properties from each of the given comma separated URLs -->
<attribute name="URLList">
./conf/path.tmview.properties
</attribute>
</mbean>
在这个文件中我定义了属性:
property-placeholder filepath=/var/tmview_props/tmview/tmview.properties
这个属性用在下面的bean定义中
<bean id="tmviewConfigurerLocation" class="org.springframework.core.io.FileSystemResource">
<constructor-arg value="${property-placeholder-filepath}" />
</bean>
在 applicationContext.xml 中。当我启动 jboss 时,会读取属性文件
15:45:29,939 INFO [SystemPropertiesService] Loaded system properties
from: file:/D:/devel/projects/tmview/deployment/jboss-
...ver/tmview/conf/path.tmview.properties
所以,该属性被读取,但我不断获得以下异常
2015-03-24 15:45:39,219 ERROR
[org.springframework.web.context.ContextLoader] Context
initialization failed
org.springframework.beans.factory.BeanInitializationException: Could
not load properties; nested exception is
java.io.FileNotFoundException: ${property-placeholder-filepath} (The
system cannot find the file specified)
at
org.springframework.beans.factory.config.PropertyResourceConfigurer.
postProcessBeanFactory(PropertyResourceConfigurer.java:78)
有什么特殊的方法可以读取 spring bean 中的属性吗?
【问题讨论】: