Article:
  Advanced Configuration of the Spring MVC Framework
Subject:   Additional way to configure
Date:   2006-03-23 02:14:30
From:   Andrew_Sazonov

Hi Dejan!


Thank you for your great article - it's very useful and it was real pleasure for me to readit.


I'd just like to note that there could be another way to configure web application. This is approach I've used and it worked find for me.


Actually, this is combination of property placeholder and ContextLoaderListener.


The project I'm worked on included several web servers which may be added dynamically. Including all possible configuration files in war or building war file for every deployment was not acceptable option due some project' requirements.


Briefly, I've used the following scheme:



  1. ContextLoaderListener was extended so during context initialization it was able to either
      load properties from properties file located on predefined location specified in web.xml (all servers has the same location of that property file, while content of it, of course, was specific for particular server) or
    • load property file from specific URL;

  2. After retrieving Properties, ContextLoaderEx simply stores PProperties it read in ThreadLocal variable.
  3. To retrieve configuraiton properties, I extended PropertyPlaceholderConfigurer and that class was able to retrieve properties from saved threadlocal.

That's all - such a solution allowed me to have single .war file for arbitrary server, but have ability to convigure them individually.


If someone is interested in details, I'll be glad to provide sample code.


I hope my solution could be helpful


Best regards,

Andrew Sazonov

SoftAMIS

http://www.soft-amis.com



Full Threads Newest First

Showing messages 1 through 2 of 2.

  • Dejan Bosanac photo Additional way to configure
    2006-03-24 02:39:26  Dejan Bosanac | O'Reilly Blogger [View]

    Hi,

    I'm glad to see that this topic is interesting to people.

    As far as managing different properties files is in question I didn't go in details there, since I wanted to describe a solution based on managing multiple applicationContex.xml files. But sure, the similar solution could be easily made.

    Andrew, I would like to see the source code of your solution.

    Maybe we can all work together on a solution that would be more general and useful to different kind of projects.


    Regards,
    Dejan
    • Additional way to configure - SAMPLE
      2006-03-24 07:55:09  Andrew_Sazonov [View]

      Hi Dejan!


      Your can download sample from this URL:



      http://www.soft-amis.com/binary/SpringConfigSample.zip



      ZIP contains sources for classes I've wrote and fragment of web.xml configuration and Spring configuration


      In this sample I've included only code that reads properties from file, but to illustrate general approach I suppose that particular way of obtaining them is not too important



      Best regards,

      Andrew Sazonov

      SoftAMIS

      http://www.soft-amis.com