I have a BeanDefinitionDecorator that makes modifications to properties that a user would set on a bean. It works fine; except if the bean is using placeholders. I am trying to find a strategy to modify those values while still have access to the original value at runtime. An example of what this would look like in XML:
<bean id="bean">
<property name="jdbcUrl" value="${jdbc.url}" />
<d:spyDecorator />
</bean>
I know that user would be writing the jdbcUrl property as “jdbc:myDatabase”. What I want to do is change their property to “jdbc:spy:myDatabase”. This is easy if they are just using string literals for the property value, but if they are using property placeholders I am not sure how to change the value — because I need the original value in order to supply the new value. They key is to keep the property rewriting transparent to the user.
Are there any possible solutions for this?
I think your namespace handler can register a
BeanFactoryPostProcessor(implementingOrdererwithorder = Integer.MAX_VALUEto be the last post processor applied). Then yourBeanDefinitionDecoratorwill register the beans being decorated for processing with that post processor (implement it in the post processor somehow), and post processor will apply the actual property modification to that beans.