Reading reloadable xml file from external Tomcat directory

对着背影说爱祢 提交于 2019-12-07 19:04:47

问题


Prerequisites

  • Apache Tomcat 7
  • Spring 3.2.11.RELEASE
  • Apache Camel 2.14.1
  • My Webapplication is deployed in ${catalina.home}/webapps/ as usual

Requirements

  • Reading xml file placed outside of war-Archive (for example from ${catalina.home}/myfolder/)
  • The xml file should be reloadable. So if the xml changes the new xml file should be available in my Webapplication
  • The xml file should be mapped to Java-Objects

First try

I have added the file to classpath via tomcat in catalina.home/conf/catalina.properties:

common.loader=${catalina.base}/lib,${catalina.base}/lib/*.jar,${catalina.home}/lib,${catalina.home}/lib/*.jar,${catalina.home}/myfolder/

The file is placed here: ${catalina.home}/myfolder/myFile.xml

Reading and mapping the file to Java-Objects works via a timer in apache camel.

from("timer://myTimer?fixedRate=true&period=20000")
.setBody(simple("resource:classpath:myFile.xml"))
.unmarshal(myFileJaxbDataFormat)
.process(myFileTimerProcessor);

myFileTimerProcessor takes the mapped Objects and stores it to a Spring-Bean. This Bean is used by other Camel-Routes to access the Data contained in the xml file.

Problem

As Claus Ibsen mentioned below the problem is that the ClassLoader caches the file. So the file is not read again if data in it has changed. If the file ${catalina.home}/myfolder/myFile.xml changes it should be read again and the new values should be available to the timer so it can read the new values for the application.

Is there a possibility to read a xml file outside of war-Archive and reload it if it's content changes?

Is there a more common wary to do that?

Thanks in advance.

Regards,

Max

EDIT 1: I have restructured the question to ask not only specific details.


回答1:


The file is cached by the Java classloader, not something Camel can do anything about. You likely need to load the file using file resources instead of classpath.



来源:https://stackoverflow.com/questions/29829601/reading-reloadable-xml-file-from-external-tomcat-directory

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!