Results 1 to 6 of 6

Thread: How to set propertyConfigurer location from system environment?

  1. #1
    Join Date
    Jun 2007
    Posts
    6

    Question 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. #2
    Join Date
    Feb 2005
    Posts
    217

    Default

    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.

  3. #3
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,425

    Default

    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 at 12:26 PM.
    Barracuda Networks SSL VPN Lead Developer
    http://pramatr.wordpress.com
    http://twitter.com/karldmoore
    http://www.linkedin.com/in/karldmoore
    Any postings are my own opinion, and should not be attributed to my employer or clients.

  4. #4
    Join Date
    Jun 2007
    Posts
    6

    Default

    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.

  5. #5
    Join Date
    Aug 2006
    Posts
    382

    Default 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.
    Greg L. Turnquist (@gregturn), SpringSource/VMware
    Project Lead: Spring Python and author of Spring Python 1.1 and Python Testing Cookbook.
    Listen to Pond Jumpers, the international podcast for open source developers.
    These comments are my own personal opinions, and do not reflect those of my company.

  6. #6
    Join Date
    Aug 2006
    Location
    Now Germany, previously Ukraine
    Posts
    1,546

    Default

    Quote 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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •