Spring Property Placeholders with String Concatenation
java, properties, spring
Solution
I solved the issue by changing `PropertyPlaceholderConfigurer` beans to `Properties`. `<util:properties/>` are accessible in SpEL.
Example: `"#{prop[host+'.'+'maxLength']}"`
where `host` is a string bean.
Problem
My problem looks simple but I'm not able to resolve it. I have a properties file which contains configuration details of all environments (dev, qa, prod). Example `config.properties`: ``` dev.maxLength=2000 qa.maxLength=4000 ``` We have a parent Properties file which holds the host name, environment mappings. Example `hosts.properties`: ``` host1=dev host2=qa ``` The property name `host1` is stored in a bean `hostname`. ``` <bean id="hostname" factory-bean="localhostInetAddress" factory-method="getHostName"/> ``` To resolve the config properties name I have to join the strings as follows, `${${**hostname**}.maxLength}` which should be resolved as `${dev.maxLength}` I tried using SpEL with no success. I am getting `Could not resolve placeholder` Exception. How can I concatenate a bean value in property place holder? How are dynamic property names constructed? Spring version 3.2