|
From: Alexi P. <apo...@ya...> - 2004-04-29 17:18:40
|
Hi all,
In Petclinic I see following in applicationContext.xml
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property
name="location"><value>/WEB-INF/jdbc.properties</value></property>
</bean>
The location property in PropertyPlaceholderConfigurer is of type
Resource. The question is, how does Spring "knows" to take
/WEB-INF/jdbc.properties string and construct an instance wich
implements a Resource interface. How does it knows what implementation
of this interface to use?
The second part of my question is a "real question". What I would like
to do is to have PropertyConfigurer to setup different property set
based on context (system property).
The reason I need it is for moving code from one environment to another.
For example when I move my app. from development to production my DB is
changing so I would like my PropertyConfigurer to read different
property file based on some system property which identifies environment.
The way I am trying to do it is by creating a special subclass of a
Resource which uses a ResourceBundle instead of single property file.
Each locale in ResourceBundle represents an environment (dev, test,
prod). My context now looks like that:
<bean id="resourceA" class="myresources.ContextualResource">
</bean>
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<ref local="resourceA"/>
</list>
</property>
</bean>
Does it sound like a resonable approach? Has somebody done it before ?
Is it better way of doing this ?
Thanks, Alexi
|