日期:2014-05-20  浏览次数:20731 次

配置文件读取java
tomcat启动时读取的文件,除了重起tomcat还有什么方法让tomcat重新读取,我的tomcat读取的xml在页面上生产一个tree,我修改时由于它是启动读取xml,修改是页面的树没有变化,求如何更改!!!!!!
页面发送的ajax请求,得到一个json,用jstree生成的树
读取时用的是spring注入
<bean id="dictParser" class="com.vinux.framework.dal.data.dict.parser.DataDictConfigParser" init-method="parse" scope="singleton">
<property name="resources">
<list>
<value>classpath:/datadict/*_DATADICT.XML</value>
</list>
</property>
</bean>
将所有的xml文件注入到一个java类中,树是根据java类的属性生成的


------解决方案--------------------
写个线程去监听xml文件的lastModified,如果变化了就重新加载。
------解决方案--------------------
Java code

public class Log4jThread extends Thread {
   private File file;
   private long lastModified;
   private final long millis = 10 * 1000L;
   
   public Log4jThread(String path) {
      setName(Log4jThread.class.getSimpleName());
      file = new File(path);
      lastModified = file.lastModified();
      PropertyConfigurator.configure(path);
   }

   public void run() {
      while(true) {
         try {
            sleep(millis);

            if(file.lastModified() != lastModified) {
               //PropertyConfigurator.configure(file.getCanonicalPath());
               DOMConfigurator.configure(file.getCanonicalPath());
               lastModified = file.lastModified();
               System.out.println("Info: The log4j.properties is reload!");
            }
         }
         catch(InterruptedException e) {
            System.err.println("Error: The log4j thread is interrupted!");
         }
         catch(IOException e) {
            System.err.println("Error: Cann't find '" + file.getName() + "'!");
         }
      }
   }
}