Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 重新加载弹簧特性_Java_Xml_Spring_Properties_Javabeans - Fatal编程技术网

Java 重新加载弹簧特性

Java 重新加载弹簧特性,java,xml,spring,properties,javabeans,Java,Xml,Spring,Properties,Javabeans,这是一个大学项目: 我正在使用Spring PropertyPlaceHolderConfigure从属性获取值 文件我正在通过以下代码从GUI更新属性文件: Properties prop = new Properties(); FileOutputStream out = null; out = new FileOutputStream("pro.properties"); prop.setProperty("durationpro", "wk"); prop.store(out, null

这是一个大学项目: 我正在使用Spring PropertyPlaceHolderConfigure从属性获取值 文件我正在通过以下代码从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();
我尝试使用两种方法使更新的文件正常工作: 我尝试在文件更新后直接刷新上下文应用程序

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>

类路径:pro.properties
我完全是为另一个Wunschdenken方法复制了xml文件


感谢您的帮助

Nevermind-我将属性文件放在源文件夹中,将其移出并实现
一切正常

我试图让xml文件识别属性文件何时被更改,并重新加载新的属性名称