Home > Uncategorized > Using Patterns to Suppliment your Spring Configuration

Using Patterns to Suppliment your Spring Configuration

November 15th, 2007 corbix

Your Spring configuration probably consists of one or more well know XML files which are loaded by name. Have you ever wanted to override something without having to touch your base configuration? Here’s what we do. After we load our base configuration we use a pattern to load any XML files which exist in a specific “configuration-override” directory. In most cases the directory is empty and just the base configuration is loaded. When we want to override a particular bean we just place a file in the override directory.Here’s a clip from the Spring API docs:

clipped from static.springframework.org

4.7.2.1. Ant-style Patterns

When the path location contains an Ant-style pattern, for example:

     /WEB-INF/*-context.xml
     com/mycompany/**/applicationContext.xml
     file:C:/some/path/*-context.xml
     classpath:com/mycompany/**/applicationContext.xml

Share and Enjoy:
  • Print this article!
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • LinkedIn
  • StumbleUpon
  • Technorati
  • TwitThis
Categories: Uncategorized Tags:
  1. darren.hicks
    November 15th, 2007 at 15:38 | #1

    This will allow for a common line of code to be much more configurable on a per-deployment basis – awesome!

    One thing, though…

    It’s probably best to use lazy-initialization on the SpringBeans to allow the overrides ( which are processed last ) to be the only implementation ever instantiated. Otherwise there may be crufty chaos and side-effects when unexpected resources are loaded, for example. Or if the overriden bean attached itself as a callback with another bean through some mechanism…

  1. No trackbacks yet.
Comments are closed.