Announcement Announcement Module
Collapse
No announcement yet.
File location for PropertyOverrideConfigurer Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • File location for PropertyOverrideConfigurer

    I want to use PropertyOverrideConfigurer with an external file that the end user can tweak easily. It is located in the same directory as the main jar of the application.

    I tried the following:

    Code:
        <bean id="propertyOverrideConfigurer"
            class="org.springframework.beans.factory.config.PropertyOverrideConfigurer">
            <property name="locations">
                <list>
                    <value>deploy.properties</value>
                </list>
    and also tried file:deploy.properties. But both do not seem to work. What is the correct syntax for picking up the file from the current directory?

  • #2
    On a related note, I'd like to have different properties files for different environments. I'd like to have them all deployed, but which one(s) we actually use for overrides I'd like to control in some way.

    Similarlly, I'd like it not to be just one file, but the union of a group of properties files that are used for overrides.

    Has anyone done anything like this?

    Comment


    • #3
      If you only specify a plain filename, then it is tried to resolve this using a classpath root folder (default behavior).
      If everything is inside your jar, and the property file resides outside (in the same folder) then you have to ensure that this folder is part of the classpath.

      You can do this by adding a class-path entry to the jar's manifest file.

      Example:
      Code:
      Class-Path: .
      Regards,
      Andreas

      Comment


      • #4
        That sounds brilliantly simple Andreas!
        Unfortunately this does not seem to work for me . I also tried with file: and classpath:

        Comment


        • #5
          I admit, I never used PropertyOverrideConfigurer, but with PropertyPlaceholderConfigurer I already managed to get this working. Maybe you can try to add an absolute path in the classpath-entry (for testing only) and see if that works.
          If yes, then the issue is maybe the invocation and what is actually being resolved as current folder.

          Regards,
          Andreas

          Comment


          • #6
            Both Override and Placeholder are subclasses of ProperyResourceConfigurer, so that should make no difference.

            An absolute path does not work either. This feels like I am overlooking something very simple.

            Comment


            • #7
              Seems like the entry is not processed correctly. Could you probably debug into the code inside the jar to verify the classpath?

              How does your manifest file look like (btw: did you build it with Ant or manually)?

              Regards,
              Andreas

              Comment


              • #8
                Andreas,

                Here is the manifest:

                Manifest-Version: 1.0
                Archiver-Version: Plexus Archiver
                Created-By: Apache Maven
                Built-By: kees
                Build-Jdk: 1.5.0_07
                Extension-Name: XXX
                Specification-Title: Xxx
                Specification-Vendor: XXX
                Implementation-Vendor: XXX
                Implementation-Title: xxx
                Implementation-Version: 0.0.1
                Main-Class: XXX
                Class-Path: . lib/jta-1.0.1B.jar lib/log4j-1.2.8.jar lib/commons-logging
                -1.0.4.jar lib/poi-2.5.1-final-20040804.jar lib/commons-beanutils-1.7 etc etc.

                It was built with the maven jar plugin.

                While debugging the java.class.path system variable only contains the main jar. Any idea how I can obtain the real classpath?

                Comment


                • #9
                  Your manifest file looks ok. As for the classpath: sometimes it works by debugging the classloader. Depending on the CL you can find out the classpath locations. Do you start your app with the "-jar" flag? And from which folder do you start it? If you manage to set the current folder to the folder containing the jar (and the properties file), it should hopefully work.

                  Regards,
                  Andreas

                  P.S.: Sorry for the delay. I have been away a few days.

                  Comment


                  • #10
                    Which BeanFactory implmentation are you using?

                    If I remember correctly, this feature only works when you're using ClassPathXMLApplicationContext. A friend of mine couldn't get it to work, asked me how mine worked and it turned out that I was using ClassPathXMLApplicationContext and he was using some other implementation (Can't remember which) - he changed his code to use ClassPathXMLApplicationContext and everything started working.

                    I also seem to remember that you had to be careful where you put the properties file, in order to ensure that the web container (Tomcat in our case) could find it.

                    And another thing - shouldn't your property references look something like this?

                    Code:
                    <value>${deploy.properties}</value>

                    Comment


                    • #11
                      I am using the ClasspathXmlAppContext.

                      The ${} syntax if for the PropertyPlaceHolderConfigurer.

                      Comment


                      • #12
                        Thanks Andreas,

                        I start the app with -jar, from the folder the jar is in.

                        Comment


                        • #13
                          Did some more digging. I created a bare bones app with the following config:
                          Code:
                              <bean id="propertyOverrideConfigurer"
                                  class="org.springframework.beans.factory.config.PropertyOverrideConfigurer">
                                  <property name="location" value="file:deploy.properties"/>
                                  <property name="ignoreResourceNotFound"    value="false"/>
                                  <property name="ignoreInvalidKeys" value="false"/>
                              </bean>
                          
                              <bean id="bean"
                                  class="Bean">
                                  <property name="property" value="original" />
                              </bean>
                          I would expect some error when the properties file is not found. But I see no error message at all. So apparently the override configurer is just not working.

                          Then I read the spring reference guid once more on the subject:

                          Just as in the case of BeanPostProcessors, you typically don't want to have
                          BeanFactoryPostProcessors marked as being lazily-initialized.
                          And that was exactly my problem My app context has the property default-lazy-init="true".
                          After defining the configurer as lazy-init="false" everything worked as expected.
                          Last edited by Kees de Kooter; Jul 17th, 2006, 06:06 AM.

                          Comment


                          • #14
                            Originally posted by Kees de Kooter
                            I am using the ClasspathXmlAppContext.

                            The ${} syntax if for the PropertyPlaceHolderConfigurer.
                            My apologies - I misread PropertyOverrideConfigurer as PropertyPlaceHolderConfigurer.

                            Comment


                            • #15
                              No problem. Thanks for your help.

                              Comment

                              Working...
                              X