Hi!
Often, I would like to use a specific property from a property file in my bean definition (using Spring 2.0.4).
If I use PropertyPlaceholderConfigurer, I will need to come up with a unique prefix/postfix, so as not to interfere with the rest of the configuration. This is not very encapsulated, and I may end up with a lot of $[], ${}, @[], @{}, #{}, #[] etc, if I need to do it several times. Can I scope the PropertyPlaceholderConfigurer to only process certain bean definitions?
Alternatively, I can use a MethodInvokingBeanFactory to call getProperty on the properties bean. But that is quite verbose (see the javadoc for MethodInvokingFactoryBean for a sample).
I ended up writing my own PropertyExtractorBeanFactory, to be used as:
Is there a simpler approach, using the standard beans?Code:<bean id="myKey" class="util.PropertyExtractorBeanFactory"> <property name="properties"> <util:properties id="myProps" location="props.properties"/> </property> <property name="key" value="myKey"/> <property name="defaultValue" value="myDefault"/> </bean>


Reply With Quote