Announcement Announcement Module
Collapse
No announcement yet.
How to set propertyConfigurer location from system environment? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to set propertyConfigurer location from system environment?

    I'm a newbie, so please bear with me. I have a myApp.properties file that is in the ${catalina.home}/conf directory.

    In my applicationContext.xml:
    <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.Pr opertyPlaceholderConfigurer">
    <property name="location" value="file:${catalina.home}/conf/myApp.properties"/>
    </bean>

    This appears to build and deploy fine. However, when I try to run a JUnit test, it cannot find the file.

    JUnit test in setup:
    ApplicationContext ac = new FileSystemXmlApplicationContext("web/WEB-INF/applicationContext.xml");

    However, if I change the location to a hard-coded path it works:
    value="file:c:\netbeans...\conf\myApp.properties". I really don't want to hard-code the location because we would have to change the applicationContext.xml when we install in a production environment. I really want the path to be relative to where Tomcat is running. When we install, we will just move the myApp.properties to the appropriate place.

    I also tried setting a System Environment property: CATALINA_HOME=c:\...
    Then in the style of ant, value="file:${env.CATALINA_HOME}\conf\myApp.proper ties". That obviously did not work.

    Is there a simple solution to this? The entries in the forums seem way more complicated than what I'm trying to do.
    Thanks.

  • #2
    Is there a simple solution to this? The entries in the forums seem way more complicated than what I'm trying to do.
    You could read a file called "build.properties" that contains a catalina.home key/value. Then add build.properties to your .cvsignore file and tell others that they must have this local configuration file in order to run the junit test.

    Or you could make your junit tests independent of the spring XML files and just wire up all the classes by yourself. That's what I do.

    Comment


    • #3
      If the files are always in the same relative location you wouldn't need to change anything. On a previous project we did use a properties file on the root of the classpath to specify the locations of various resources. Not sure it was the best solution.
      Last edited by karldmoore; Aug 29th, 2007, 12:26 PM.

      Comment


      • #4
        The myApp.properties are in the same place relative to Tomcat, but Tomcat is in a different place on different machines. That's why I wanted to find a way to specify the tomcat location as variable.

        Comment


        • #5
          Create footprint-specific properties files

          We have a system environment variable called footprint. I have a footprint_dev.properties, footprint_test.properties, footprint_production.properties file, and so forth. Then, I have a PropertyPlaceholderConfigurer that loads up classpathroperties_${footprint}.properties. This lets me have a development lab version of everything, a test lab version, and a product version without rewriting any bean configurations or having to hand-edit things at deployment. I just have to have that system property variable set in each target environment to tip my code off on which properties to utilize.

          Comment


          • #6
            Originally posted by kcgdit View Post
            I'm a newbie, so please bear with me. I have a myApp.properties file that is in the ${catalina.home}/conf directory.

            ...
            And your application is ${catalina.home}/webapps/myApp directory?

            So try to specify path to the properties file as ../../conf/myApp.properties

            It should help.

            Comment

            Working...
            X