Spring PropertyPlaceholderConfigurer with dynamic location path -


i have following spring xml-based config:

<!--   these properties define db.type property. --> <bean class="org.springframework.context.support.propertysourcesplaceholderconfigurer">   <property name="order" value="1"/>   <property name="ignoreunresolvableplaceholders" value="true" />   <property name="ignoreresourcenotfound" value="true" />   <property name="locations">     <list>       <!-- contains default db.type -->       <value>classpath:/default-cfg.properties</value>       <!-- db.type can overridden optional properties in app work dir -->       <value>file:${app.work.dir}/cfg.properties</value>     </list>   </property> </bean>  <!-- db.type should used db specific config properties --> <bean class="org.springframework.context.support.propertysourcesplaceholderconfigurer">   <property name="order" value="2"/>   <property name="ignoreunresolvableplaceholders" value="false" />   <property name="ignoreresourcenotfound" value="false" />   <property name="locations">     <list>       <!-- not work, ${db.type} not resolved -->       <value>classpath:/default-cfg-${db.type}.properties</value>     </list>   </property> </bean> 

the problem property in classpath:/default-cfg-${db.type}.properties location not resolved though db.type defined first property placeholder configurer.

i keep getting following error in log:

 class path resource [default-cfg-${db.type}.properties] cannot opened because not exist 

is there way use properties in propertyplaceholderconfigurer's locations attribute? want avoid using jvm system property set db.type value.

thank you, jan

both postprocessors instantiated, orderer , executed, second pspc instantiated before first 1 executed.

if first pspc implements beandefinitionregistrypostprocessor run before second 1 instantiated , work expect.

for example:

public class beandefinitionregistryplaceholderconfigurer extends propertysourcesplaceholderconfigurer      implements beandefinitionregistrypostprocessor {      @override     public void postprocessbeandefinitionregistry(beandefinitionregistry registry) throws beansexception {         // nothing todo, run before other pphcs instantiated     } } 

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -