I always hate it when I see a project with confi settings in env variables, properties files, and the myriad of XML deployment descriptors.
Spring has helped out a lot with its PropertyPlaceholderConfigurer that allows you to put everything in one place (like a properties file or three) and suck them out into ${variables}.
How about getting values into something like a web.xml?
One generic solution is to use your build system do the work for you.
With ant, you can use filters and when you copy over certain files, ant can do the s/SOME_VALUE/the real value/g.
E.g.
Turn on filtering when you copy
<copy todir=”${build.web.dir}/WEB-INF/classes” filtering=”true”>
<fileset dir=”${resources.dir}”/>
</copy>
Setup tokens to filter on
<filter token=”smtpHost” value=”${smtpHost}”/>
…
Juergen just added a new class to what will be Spring 1.1.4: ServletContextPropertyPlaceholderConfigurer.
This class looks into the web.xml for <context-param>’s if the ${value} isn’t found. This isn’t the same as the other solution, as the core value is now in the web.xml, rather than having everything in ONE place, and pushing that to the other config files.
January 4th, 2005 at 12:57 pm
Ant has a built-in property filter that works MUCH better than manually filtering tokens.
<property file=”spring.properties”/>
<copy todir=”${test.build.dir}” overwrite=”true”>
<fileset dir=”${conf.dir}/spring/test” includes=”*Context.xml”/>
<filterchain>
<expandproperties/>
</filterchain>
</copy>
December 16th, 2006 at 11:08 am
useful information)))