0

I want to read an external properties file when launching Jboss 4.2 . I want to add it to the classpath to read it from a WAR file . I have seen different solutions with Jboss 6 using modules, but I haven't seen anything related to JBoss 4.2.

I have included inside 'jboss-service.xml' the following code :

    <!-- 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 id="tmviewConfigurerLocation"   class="org.springframework.core.io.FileSystemResource">
      <constructor-arg value="${property-placeholder-filepath}" />
   </bean>

inside an applicationContext.xml . When I launch jboss, the file of properties is read

    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 ?

Artjom B.
  • 61,146
  • 24
  • 125
  • 222
Yago
  • 319
  • 1
  • 3
  • 18

2 Answers2

0

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.

Another possibility is add your custom directory to the classpath, to do this see Adding second conf folder to JBoss 5.1.0

Community
  • 1
  • 1
Federico Sierra
  • 5,118
  • 2
  • 23
  • 36
  • I have tried to put the file in conf with no results . The same adding a second conf folder . – Yago Mar 24 '15 at 16:11
0

Ok . At the end , I solved the problem . It seems the problem was located in reading from 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 .

Yago
  • 319
  • 1
  • 3
  • 18