You can use PropertyPlaceholderConfigurer
to substitute property values for placeholders in bean properties, aliases, and other places. Note that the replacements happen AFTER the bean definitions have been loaded, so this mechanism does not apply to <import>
elements
For example:
...
<bean id="ppc"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:build.properties</value>
<value>classpath:default-emmet-substitution.properties</value>
<value>classpath:default-danno-substitution.properties</value>
<value>classpath:default-dannotate-substitution.properties</value>
<value>classpath:substitution.properties</value>
</list>
</property>
</bean>
...
For more information refer to this section of the Spring Framework docs.
EDIT - I guess from your comment you are already familiar with how placeholder replacement works, and are using PropertyPlaceholderConfigurer
to do the replacements. So now you need to choose between these strategies, or some combination:
Do the placeholder replacements yourself in your custom BeanDefinitionDecorator
. That would work, though you'd be duplicating a lot of code.
Have the custom BeanDefinitionDecorator
modify the placeholder names to different ones that will pull in different values; e.g. "${jdbc.url}"
becomes "${spy.jdbc.url}"
.
Extend the PropertyPlaceholderConfigurer
class to modify the substituted property values; i.e. override convertProperty
or convertProperties
. That has the potential problem that all placeholders will get the modified values ... not just the ones in beans that you have decorated.
Create a new PropertyResourceConfigurer
class to substitute different property values depending on the context. Essentially, the processProperties
needs to work like the method does in a PropertyPlaceholderConfigurer
, but do something different if it sees bean properties or whatever that tell it to do the "spy" substitution.
A combination of 2) and 3) looks the most promising.