首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2EE开发 >

配置文件读取java解决办法

2012-01-01 
配置文件读取javatomcat启动时读取的文件,除了重起tomcat还有什么方法让tomcat重新读取,我的tomcat读取的x

配置文件读取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() + "'!");         }      }   }} 

热点排行