从外部Tomcat的目录中读取重载xml文件 [英] Reading reloadable xml file from external Tomcat directory

查看:331
本文介绍了从外部Tomcat的目录中读取重载xml文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

prerequisites


  • 的Apache Tomcat 7

  • 春3.2.11.RELEASE

  • Apache的骆驼2.14.1

  • 我的web应用部署在$ {}的catalina.home / webapps /下照常

要求


    放在外战 - 归档
  • 读取XML文件(例如,从$ {}的catalina.home / MyFolder中/)

  • XML的文件应该是的重新加载。因此,如果XML改变了新的XML文件应该是在我的web应用提供

  • XML文件应为映射到Java对象

第一次尝试

我添加文件到tomcat的通过在类路径的catalina.home /conf/catalina.properties:

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

该文件被放在这里:
$ {}的catalina.home /myfolder/myFile.xml

阅读和映射文件到Java对象通过在Apache的骆驼定时器工作。

 从(计时器:// myTimer固定利率=真放;周期= 20000)
.setBody(简单(资源:类路径:将myfile.xml))
.unmarshal(myFileJaxbDataFormat)
.process(myFileTimerProcessor);

myFileTimerProcessor需要映射的对象,并将其存储到一个Spring的Bean。
这个bean由其他骆驼路由访问包含在XML文件中的数据。

问题

作为克劳斯易卜生提到的问题下面是ClassLoader的缓存文件。因此,如果在它的数据已经改变的文件不被再次读取。
如果文件$ {的catalina.home} /myfolder/myFile.xml改变应再次读取和新的值应提供给定时器,因此它可以为应用程序读出的新的值。

有读取XML文件战争 - 归档之外,并重新加载它,如果它的内容发生变化的可能?

有没有一种较为常见的警惕这样做呢?

先谢谢了。

问候,

最大

编辑1:
我已经重新调整了要问的问题不仅是具体的细节。


解决方案

该文件是由Java类加载器缓存,不是骆驼可以做任何事情。您可能需要使用的,而不是类路径的文件资源加载文件。

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.

这篇关于从外部Tomcat的目录中读取重载xml文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆