Announcement Announcement Module
Collapse
No announcement yet.
Configuration / Deployment question Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Configuration / Deployment question

    Hi,

    We're running into a problem with Spring and configuration when deploying our war file and needing to customize some of the properties within it.

    For example, we need to set an ip address for one of our classes that Spring initializes which will be different in each customer's situation. Loading the applicationContext.xml during startup will throw lots of errors if this is not set correctly, but it's difficult to update the properties in the war before deployment. Obviously as a web app, putting the properites outside of the war is not an option.

    I would have thought this is a fairly common problem, and was wondering how people deal with it?

    cheers,

    David

  • #2
    Search for PropertyPlaceholderConfigurer in the forums.

    Check out samples/jpetstore/war/WEB-INF/applicationContext.xml.

    It basically injects variables defined in the xml files with values from the properties file.

    Dino

    Comment


    • #3
      I haven't dealt with this problem myself. But it doesn't seem to be wrong to add a property file outside of the WAR file. Just put it somewhere on the classpath and have a PropertyPlaceholderConfigurer load it.

      Comment


      • #4
        Ummm...not sure you understood my post.

        My problem is how to change the properties in the properties file in the war BEFORE deployment.

        cheers,

        David

        Comment


        • #5
          My first reply was to hucmuch.

          wpoitras - where would you put it outside the war file? The war IS the web application. Putting it outside would mean putting it outside the web application, which can't be right, and would present problems even getting access to it.

          cheers,

          David

          Comment


          • #6
            Originally posted by hay7777
            where would you put it outside the war file? The war IS the web application. Putting it outside would mean putting it outside the web application, which can't be right, and would present problems even getting access to it.
            You could put anywhere. As long as your servlet container startup added that directory to the classpath, I believe the war file would be able to pick up the property file. I guess it depends how much control you have over startup and deployment.

            Comment


            • #7
              Hi,

              Yeah, we could.

              It just seems ugly to me, and breaks the encapsulation of the webapp.

              cheers,

              David

              Comment


              • #8
                You can extend PropertyPlaceholderConfigurer to read the properties from the database.

                Check http://spring-config.sourceforge.net for approaches on configuring properties.

                BTW: the way I have dealt with it in the past is to have the properties outside the war file. You have to in certain circumstances because you may want to modify the properties at run-time and packaging properties as part of the war file won't allow for this.

                Dino

                Comment


                • #9
                  If you are just looking at configuring one value spring-config/extending PropertyPlaceholderConfigurer might be a bit much. I wrote spring-config to solve http://forum.springframework.org/showthread.php?t=15674 kind of problem.

                  Have a look at spring's ServletContextPropertyPlaceholderConfigurer class. It allows you to configure beans using web.xml context-params and properties files.

                  Cheers,
                  Dan
                  Last edited by robyn; May 16th, 2006, 04:01 AM.

                  Comment


                  • #10
                    Hi,

                    Isn't this a job for Ant?

                    I need different settings for different environments so I have Ant set up to select the appropriate property file and place into the war (in the classes directory where Spring can get at it).

                    Cheers

                    Rakesh

                    Comment

                    Working...
                    X