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>

我完全为其他 Wunschdenken 方法复制了 xml 文件

谢谢你的帮助

4

1 回答 1

0

没关系 - 我在源文件夹中有属性文件,将其移出并实现 http://commons.apache.org/configuration/并且一切正常

于 2013-01-22T11:39:27.817 回答