Webapp Configuration – the Spring Way

November 8, 2007 | by Geoff

Most Java applications will need some context specific configuration when deploying to a certain environment. This configuration could be username, password and JDBC URL for a specific database configuration or the details of an SMTP server for java mail deployments amongst others.

There are many ways to to provide runtime configurations for Java applications. For web applications, two popular mechanisms are the use JNDI configurations managers and using properties files. Both mechanisms have their limitations and caveats.

When using The Spring Framework, we are presented with a few more options to enable configuring web app projects.

The traditional approach involves using property placeholders which are then munged at runtime with a specific properties file to ensure the placeholders have valid values before executing the application. Another approach is using the newer (Spring 2.0) PropertOverrideConfigurer to override pbean definition properties at application startup. This approach allows the default spring config file to be usuable w/out needing a valid property file as no placeholders exist in the config itself but properties are merely overridden at runtime if need be. This is slightly nicer as it means that a default spring context XML config file will run w/out needing any special property merging. This allows for projects to be run within an IDE (like Eclipse) without having to jump through hoops or run special ant/maven targets to stick the correct properties file in the classpath when wanting to run your app embedded in Eclipse.

Essentially, the default Spring context configuration will work out of the box but can be overridden at runtime with other property file based properties to ensure things run properly at deployment. It’s not that dissimilar to the PropertPlaceholderConfigurer but allows for an easier workflow when wishing to work seamlessly with an IDE.

Not sure if any of this makes sense but there is more info out on the InterWeb:

Bookmark and Share

Tags: ,

Leave a Reply