[英]How to add external properties file to classpath in jboss 4.2
I want to read an external properties file when launching Jboss 4.2 . 我想在启动Jboss 4.2时读取一个外部属性文件。 I want to add it to the classpath to read it from a WAR file . 我想将其添加到类路径以从WAR文件读取它。 I have seen different solutions with Jboss 6 using modules, but I haven't seen anything related to JBoss 4.2. 我看到了使用模块的Jboss 6的不同解决方案,但是我还没有看到与JBoss 4.2相关的任何信息。
I have included inside 'jboss-service.xml' the following code : 我在“ 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>
In this file I have defined the property : 在此文件中,我定义了属性:
property-placeholder filepath=/var/tmview_props/tmview/tmview.properties
This property is used in the following bean definition 此属性在以下bean定义中使用
<bean id="tmviewConfigurerLocation" class="org.springframework.core.io.FileSystemResource">
<constructor-arg value="${property-placeholder-filepath}" />
</bean>
inside an applicationContext.xml . 在applicationContext.xml中。 When I launch jboss, the file of properties is read 当我启动jboss时,读取属性文件
15:45:29,939 INFO [SystemPropertiesService] Loaded system properties
from: file:/D:/devel/projects/tmview/deployment/jboss-
...ver/tmview/conf/path.tmview.properties
So, the property is read, but I kept obtaining the following exception 因此,该属性被读取,但是我一直在获取以下异常
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)
Is there any special way to read the property inside the spring bean ? 有什么特殊的方法可以读取spring bean内部的属性吗?
In jboss 4 you was able to drop property files in the <jboss_home>/server/<instance>/conf
directory and they would be available from the classpath. 在jboss 4中,您可以将属性文件拖放到<jboss_home>/server/<instance>/conf
目录中,并且可以从类路径中使用它们。
Another possibility is add your custom directory to the classpath, to do this see Adding second conf folder to JBoss 5.1.0 另一种可能性是将您的自定义目录添加到类路径,请参见将第二个conf文件夹添加到JBoss 5.1.0。
Ok . 好 。 At the end , I solved the problem . 最后,我解决了这个问题。 It seems the problem was located in reading from application-context.xml . 看来问题出在从application-context.xml读取。
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location">
<value>file:${tmview.conf.variables}</value>
</property>
</bean>
I had to add a property placeholder reader . 我必须添加一个属性占位符阅读器。 Regarding to jboss, you can read the parameter file either from conf/jboss-service.xml or deploy/properties-receive.xml, but it seems more appropiate to do the reading from the second one . 关于jboss,您可以从conf / jboss-service.xml或deploy / properties-receive.xml中读取参数文件,但是从第二个文件中读取内容似乎更合适。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.