Tejus's Programming and startup blog

  • Archive
  • RSS
  • Ask me anything

Using Noah to Configure Properties in your Spring Container

On a recent trip through our code base, I realized that there were multiple projects that used identical properties defined in files that sat on the file system. I find DRY is a superior pattern to copy and paste I wanted to consolidate these into a single location.

One approach would be to move them up a level in the source stack, and either rely on the properties being included in a jar or included via the build process. Both of these approaches suffer from some drawbacks and require rebuilds on a config change. Also the properties are still located all over the place, making it difficult to recover from mistakes or handle changes to the environment.

One of my co-workers, John Vincent, is currently developing Noah which is a lightweight node/service registry. However, there’s nothing that says you couldn’t use it as a centralized location for properties files.

I uploaded my properties file using Noah’s Ephemeral API. From there, it was a very trivial to make the properties available to Spring:

http://gist.github.com/1271788

However, I didn’t like the url hardcoded in the configuration file. I’d prefer to have them configured through some properties that do live on the filesystem. In effect, each server would just need to know where to go to configure themselves. This required more advanced Spring trickery. Since all PropertyPlaceholderConfigurer instances implement PriorityOrder, they will be implemented before any property expansion has become. Therefore, you have to create your own Ordered bean that wraps a PropertyPlaceholderConfigurer. The following code is adapted from this discussion forum.

http://gist.github.com/1271808

Then you configure it in your applicationContext.xml file like the following:

https://gist.github.com/1271812

Now, you just have to manage one file on the filesystem that points to where the rest of the application’s configs can be found.

    • #noah
    • #java
    • #spring
  • 7 months ago
  • 13
  • Comments
  • Permalink
  • Share
    Tweet

13 Notes/ Hide

  1. tejustechblog posted this

Recent comments

Blog comments powered by Disqus
← Previous • Next →

About

Avatar

I'm Tejus Parikh and this is my blog about programming, startups, and other technology related topics.

The vast majority of the posts are about Java or Ruby code, with a few about startups or gadgets thrown in for color.

You can learn more about me on Github and my personal homepage.

Me, Elsewhere

  • @vi_jedi on Twitter
  • Facebook Profile
  • Linkedin Profile
  • vijedi on github

Twitter

loading tweets…

  • RSS
  • Random
  • Archive
  • Ask me anything
  • Mobile

Effector Theme by Carlo Franco.

Powered by Tumblr