0
这是用于大学项目: 我使用Spring PropertyPlaceholderConfigurer从属性 文件获取值。我更新通过下面的代码的性质从GUI文件:重新加载弹簧属性
Properties prop = new Properties();
FileOutputStream out = null;
out = new FileOutputStream("pro.properties");
prop.setProperty("durationpro", "wk");
prop.store(out, null);
out.flush();
out.close();
我已经使用两种方法来获取更新的文件工作的尝试: http://www.wuenschenswert.net/wunschdenken/archives/127 ,我试图直接将文件后刷新背景应用更新
ApplicationContext f = new FileSystemXmlApplicationContext("Bean1.xml");
((ConfigurableApplicationContext)f).refresh();
我的代码
ApplicationContext context = new ClassPathXmlApplicationContext("Bean1.xml");
BeanFactory factory = (BeanFactory) context;
TestGUI t = (TestGUI) factory.getBean("testbean");
当应用程序运行(我不哈已关闭应用程序)我必须手动打开并关闭属性文件,然后才能识别更改。这里面有两种方法
的XML文件,我使用的弹簧刷新方法是:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
<bean id="propertyPlaceholderConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:pro.properties</value>
</list>
</property>
</bean>
<bean id="com" class="Domestic" />
<bean id="wk" class="Week" />
<bean id="mth" class="Month" />
<bean id="testbean" class="TestGUI">
<property name="customerType" ref="com" />
<property name="duration" ref="${durationpro}"/>
</bean>
</beans>
我正好复制了XML文件的其他Wunschdenken方法
感谢您的帮助
你的追求是什么? –
我想让xml文件识别属性文件已更改并重新加载新属性名称持续时间 –