Monday, March 15, 2010

Externalizing configuration properties

Generally, for deployment specific configurations we would like to move them out of spring specific configuration files and into a properties file.The purpose of the bean-wiring file is to define the relationships between dependent objects, and should not be used to define deployment configurations.

I've come across 2 ways to Externalize configuration properties and it really depends on the technologies you have at your disposal.

They both acheive the same result of externalizing configuration properties, except that Maven has the added benefit of using Profiles to select an appropriate build. For example, you can have one profile for creating a test build and another profile for a production build.

Preferrably, I like to use the Maven Resource filtering strategy, because it allows you to easily create a different build depending on the type of deployment you'd like to use based on Maven Profiles. Here's a good quote describing Maven resource filtering:

You can use Maven to perform variable replacement on project resources. When resource filtering is activated, Maven will scan resources for references to Maven property references surrounded by ${ and }. When it finds these references it will replace them with the appropriate value in much the same way the properties defined in the previous section can be referenced from a POM. This feature is especially helpful when you need to parameterize a build with different configuration values depending on the target deployment platform.

No comments:

Post a Comment