I almost got this working. I can't find a way to reference the properties directly using EL or to reference the PropertyPlaceholderConfigurer. So we created a PropertiesFactoryBean which can be accessed via EL and used this as the source for the PropertyPlaceholderConfigerer.
Problem #1: Difficult to access properties with dots in their name
All of the examples of @Value show properties with no dots. So for example:
Code:
@Value("#{myProps.clientDir}")
But if the property has a dot in it, this doesn't work:
Code:
@Value("#{myProps.client.dir}")
After some experimenting, I finally figured out that the solution is to use this syntax:
Code:
@Value("#{myProps['client.dir']}")
This is a lot more verbose than the old property configurer. I'd love if it just looked like this:
Code:
@Value("client.dir")
Any validation on the best way to do this?
Problem #2: Properties that reference other properties
Using PropertyPlaceholderConfigurer, we used to have properties that built on other properties. Then we could change the base property at runtime and have that change cascade through other properties. Here's an example:
Code:
base.dir = /my/dir
client.dir = ${base.dir}/clients
Then we'd inject these into objects like this:
Code:
<property name="clientDir" value="${client.dir}"/>
Based on my solution to Problem #1 above, when I first injected the property I set a breakpoint and saw that clientDir property was being set to "${base.dir}/clients" which means that the nested property wasn't being evaluated. So I tried updating my property values to match EL syntax:
Code:
base.dir = /my/dir
client.dir = #{config['base.dir']}/clients
This is uglier, but if it works, it works. But it doesn't work - the nested property also does not get evaluated using this approach.
Any ideas or recommendations?