1

One application I'm working on has several URLs and other information that is instance specific. The first pass uses a typical Spring PropertyPlaceholderConfigurer with a properties file:

<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="location" value="classpath:application.properties"/>
</bean>

The main issue with this is of course the property file is an artifact that must be checked in, and for starting a new instance would require updating that artifact. For a streamline deployment, I would like to have the ApplicationContext bootstrap itself based on database table(s). I have seen solutions like this forum post, does anyone here know of better tools or is this defacto approach to this problem? I would also like to be able to update/reload the settings at runtime using JMX or other facilities, but having to restart the app after changes to the database would still be a better solution to the current one.

Greymeister
  • 312
  • 4
  • 12
  • +1: I'm also trying to do something like this in my application. While I have a solution to this, it's huge and complex and *very* inelegant so I'm rather keen on seeing if there's a better way. – Donal Fellows Mar 11 '11 at 09:18
  • I found [this](http://stackoverflow.com/questions/4599252/how-to-configure-a-spring-beans-with-properties-that-are-stored-in-a-database-tab/4601913#4601913) Post by @sean-patrick-floyd using that in the configuration still left me with a chicken-egg problem of loading database properties from a file and other properties from the database in the same ApplicationContext. – Greymeister Mar 11 '11 at 14:17

1 Answers1

0

The way we did it was to put some configuration information in the environment and then pull the relevant info from there.

<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
   <property name="searchSystemEnvironment" value="true" />
</bean>

If configuration changes then the app will need to be restarted. Can also put all the different configurations into the environment and nest the variables like the following:

<bean id="db" class="org.DataSource"
        p:databaseServer="${${MODE}_DBSERVER}"
        p:databaseName="${${MODE}_DBNAME}" />

where $MODE = dev, qa, etc.

Victor Parmar
  • 5,719
  • 6
  • 33
  • 36