I am working on a Spring 2.0 project without annotations. We use several PropertyPlaceholderConfigurer beans with different pre and suffixes to load properties from different property files. It works great.
Due to the large number of properties and properties files, I wanted the application to display properties that were not used . This means that properties that are configured in the properties file, but are never mentioned in the context of the Spring application.
I wrote a bean that implements BeanFactoryPostProcessor, and did some tricks to find links in the application context for different PropertyPlaceHolderConfigurers. This gives me a list of properties that are being used.
However, I cannot go over to the properties that were loaded by the PlaceHolderConfigurers platform. Because of this, I cannot show properties that are NOT used.
Is there a (simple) way to get PropertyPlaceholderConfigurer properties? Any other suggestions to solve this?
Change The solution got access to the mergeProperties method, for example:
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 initially loaded properties and getting beandefinitions during BeanFactoryPostProcessing, the rest was simple. Subtract the two collections and voila: now we can list the unused properties.
java spring
Rolf
source share