【问题标题】:Reload Spring Properties重新加载弹簧属性
【发布时间】:2013-01-21 18:56:30
【问题描述】:

这是一个大学项目: 我正在使用 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"); 

当应用程序运行时(我不必关闭应用程序),我必须手动打开和关闭属性文件,然后才能识别更改。两种方法都会发生这种情况

我用于spring刷新方法的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 文件

感谢您的帮助

【问题讨论】:

  • 我正在尝试让 xml 文件识别属性文件何时更改并重新加载新的属性名称持续时间

标签: java xml spring properties javabeans


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-12-15
    • 2015-11-12
    • 2018-01-16
    • 2019-06-09
    • 2023-03-28
    • 1970-01-01
    • 2022-10-21
    • 1970-01-01
    相关资源
    最近更新 更多