I have a static file that I want to load properties from on the fly and I would like the bean to retain the changes to the properties after I load them so that I can utilize them again later. An example of data in it might be a list of people you want to email that might change. So, I get the bean from the application context and then I load the properties in a configured bean but the properties don't stay when I fetch the singleton again.
Does anyone know of a way that I can do this?
properties file:
MyPropertyUtil class:Code:email.list=test@test.com,emailme@test.com
Code that calls MyPropertyUtil class:Code:public class MyPropertyUtil { private Properties properties; public MyPropertyUtil() { properties = new Properties(); } public boolean loadProperties() { //code to read from a file and iterate over each line to load in properties String[] keyAndValue = line.split("="); this.properties.put(keyAndValue[0], keyAndValue[1]); } }
bean configuration in applicationContext.xmlCode:BeanFactory beanfactory = new ClassPathXmlApplicationContext("applicationContext.xml"); MyPropertyUtil propertyUtil = (MyPropertyUtil) beanfactory.getBean("myPropertyUtil"); //Call to update a property on the MyPropertyUtil of type java.util.Properties myPropertyUtil.loadProperties();
Code:<bean name="myPropertyUtil" class="com.util.MyPropertyUtil"></bean>


Reply With Quote
