【问题标题】:How to add external properties file to classpath in jboss 4.2如何在 jboss 4.2 中将外部属性文件添加到类路径
【发布时间】: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 中的属性吗?

【问题讨论】:

    标签: java jboss


    【解决方案1】:

    在 jboss 4 中,您可以将属性文件拖放到 &lt;jboss_home&gt;/server/&lt;instance&gt;/conf 目录中,它们可以从类路径中获得。

    另一种可能性是将您的自定义目录添加到类路径中,请参阅Adding second conf folder to JBoss 5.1.0

    【讨论】:

    • 我试图将文件放入 conf 中,但没有结果。同样添加第二个 conf 文件夹。
    【解决方案2】:

    好的。最后,我解决了这个问题。似乎问题出在从 application-context.xml 中读取。

    <bean id="propertyConfigurer"   
      class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="location">
                <value>file:${tmview.conf.variables}</value>    
        </property>
    </bean>
    

    我必须添加一个属性占位符 reader 。关于 jboss,您可以从 conf/jboss-service.xml 或 deploy/properties-receive.xml 读取参数文件,但从第二个读取参数文件似乎更合适。

    【讨论】:

      猜你喜欢
      • 2016-04-03
      • 2013-02-27
      • 1970-01-01
      • 2012-04-29
      • 2019-09-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-08
      • 2013-08-27
      相关资源
      最近更新 更多