当前位置: 代码迷 >> J2EE >> 配置文件读取java解决办法
  详细解决方案

配置文件读取java解决办法

热度:157   发布时间:2016-04-22 02:47:56.0
配置文件读取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() + "'!");         }      }   }}
  相关解决方案