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.
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