The Artima Developer Community
Sponsored Link

Java Buzz Forum
Multiple, separate PropertyPlaceholderConfigurers in Spring

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Chris Winters

Posts: 931
Nickname: cwinters
Registered: Jul, 2003

Daytime: Java hacker; nighttime: Perl hacker; sleeptime: some of both.
Multiple, separate PropertyPlaceholderConfigurers in Spring Posted: Jul 26, 2005 1:02 PM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by Chris Winters.
Original Post: Multiple, separate PropertyPlaceholderConfigurers in Spring
Feed Title: cwinters.com
Feed URL: http://www.cwinters.com/search/registrar.php?domain=jroller.com®istrar=sedopark
Feed Description: Chris Winters on Java, programming and technology, usually in that order.
Latest Java Buzz Posts
Latest Java Buzz Posts by Chris Winters
Latest Posts From cwinters.com

Advertisement
several PropertyPlaceholderConfigurer instances in a AppCtx? - I'm building a custom lightweight application server at work with Spring as its core. Any number of applications can be deployed to it; they're discovered at runtime so deployment is a file-copy. Each application has its own Spring context and settings and to ensure we have writable configuration in an easy-to-read format some of the bean settings are brought in at runtime from properties files. Spring provides the PropertyPlaceholderConfigurer for this, so that's easy glue. (Dion had a good post about this almost a year ago.)

However, if you want to reference multiple configurers that don't know about each other you'll run into a problem. At first it will appear that you can only define one configurer because some settings won't be replaced properly, but that's a red herring. What happens is that behind the scenes Spring associates each configurer with parsing rules so it knows which configurer is supposed to replace which placeholders. Therefore you've got to provide some disambiguation to this parser. Fortunately it's easy:

    <bean id="appASettings" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="location" value="appA_settings.properties" />
        <property name="placeholderPrefix" value="$A{" />
    </bean>
  
    <bean id="appADataSource" 
        class="org.apache.commons.dbcp.BasicDataSource"
        destroy-method="close">
        <property name="driverClassName" value="$A{db.driver}" />
        <property name="url"             value="$A{db.url}" />
        ...

As long as every application has its own prefix its settings will never get stomped on by any other and you can presumably add as many configurers as you need. What's most interesting about this is that the complexity behind this is only revealed if you need it. IMO most open-source projects -- and, to a lesser extent, all software -- have a hard time with this principle, burdening you with lots of configuration to do even simple things.

Read: Multiple, separate PropertyPlaceholderConfigurers in Spring

Topic: Mason "Chops" Carroll & Coté [Flickr] Previous Topic   Next Topic Topic: College matters... sometimes

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use