I'm working on a Spring 2.0 project, without annotations. We're using several PropertyPlaceholderConfigurer beans with different pre- and suffixes to load properties from different property files. This works beautifully.
Because of the large number of property files and properties, I wanted the application to list the properties which are not used. That means, properties which are configured in a property file, but never referenced in the Spring application context.
I wrote a bean which implements BeanFactoryPostProcessor, and did some trickery to find references in the application context to the different PropertyPlaceHolderConfigurers. This gives me a list of properties which are used.
However, I can not get to the properties which were loaded by the PlaceHolderConfigurers. Because of that, I can not show the properties which are NOT used.
Is there a (simple) way to get to the properties of a PropertyPlaceholderConfigurer? Any other suggestions on how to solve this problem?
Edit: The solution was accessing the mergeProperties metod, like so:
PropertyPlaceholderConfigurer ppc =
(PropertyPlaceholderConfigurer) applicationContext.getBean("yourBeanId");
Method m = PropertiesLoaderSupport.class.getDeclaredMethod("mergeProperties",
new Class[] {});
m.setAccessible(true);
Properties loadedProperties = (Properties) m.invoke(propertyPlaceHolder, null);
After getting the originally loaded properties, and fetching the beandefinitions during the BeanFactoryPostProcessing, the rest was simple. Subtract the two collections, and voila: We can now list the unused properties.