Issue Details (XML | Word | Printable)

Key: SPR-2335
Type: Improvement Improvement
Status: Open Open
Priority: Trivial Trivial
Assignee: Unassigned
Reporter: Alin Dreghiciu
Votes: 0
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
Spring Framework

PropertiesGetterFactoryBean

Created: 24/Jul/06 07:26 AM   Updated: 19/Sep/06 05:06 AM
Component/s: None
Affects Version/s: None
Fix Version/s: None

Time Tracking:
Not Specified

File Attachments: 1. Java Source File PropertiesGetterFactoryBean.java (9 kB)
2. Java Source File PropertiesGetterFactoryBeanTests.java (8 kB)



 Description  « Hide
It is sometimes usefull to get a property from a java.util.Properties and you can not use the PropertyPlaceholderConfigurer. Such a situation can happen for example when a direct or indirect reference will come from a PropertyPlaceholderConfigurer/PropertyOverrideConfigurer. In that case the only solution )I see and found also on the forums) is to create a child context. An example of this situation can be sean at http://forum.springframework.org/showthread.php?t=15583.
To be able to handle such a situation in one context and still be able to read the database setting from a properties file the values can be read from the properties by using MethodInvokingFactoryBean. The problem is that the configuration is too verbose for just retriving one value and that the class is to "heavy" fro this purpose.

So, my sugestion is to have a FactoryBean that can be used in the same manner as FieldRetrievingFactoryBean and using the name to specify the property object and static key. e.g.:

<bean name="myProperties[myKey]" class="org.springframework.beans.factory.config.PropertiesGetterFactoryBean"/>

In that case the value can be refered with something like ref="myProperties[myKey]"

I already have such a factory bean + JUnit and I can donate it.


 All   Comments   Work Log   Change History   FishEye   Builds      Sort Order: Ascending order - Click to sort in descending order
Rick Evans added a comment - 24/Jul/06 07:40 AM
Sounds good. Contribute away :)

Chris Lee added a comment - 15/Sep/06 03:06 PM

Alin Dreghiciu added a comment - 19/Sep/06 05:06 AM
The main reaseon for having this factory bean is to be used in those cases that you have a PropertyPlaceholderConfigurer/PropertyOverrideConfigurer or a refrenced bean (as the org.apache.commons.configuration.ConfigurationConverter in http://forum.springframework.org/showthread.php?t=15583) that needs the same kind of placeholders functionality as this two ...Configurers provides. And since Spring is loading BeanFactoryPostProcessor's all at once from the same context, using the ${} in a PlaceHolderConfigurer or referenced bean will not help since it is too late (the object containing ${} placeholder it is already loaded and the value is not replaced since the postProcessBeanFactory method was not yet called).
In my view the RuntimeEnvironmentPropertiesConfigurer is very usefull but is aimed to a different use case. Please correct me if I'm wrong by posting a example that solves the use case of having a PropertyPlaceholderConfigurer that takes the values from a database and the datasouce refrencing the database to take his properties from a properties file)