【问题标题】:copy file using spring integration使用弹簧集成复制文件
【发布时间】:2011-02-04 13:57:40
【问题描述】:

如何使用 spring 集成将文件从一个地方复制到另一个地方。就我而言,我想将战争之外的文件复制到战争内部。这是我正在考虑的代码sn-p:

<?xml version="1.0" encoding="UTF-8"?>

<beans:beans xmlns:beans="http://www.springframework.org/schema/beans" 
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xmlns="http://www.springframework.org/schema/integration"
             xmlns:file="http://www.springframework.org/schema/integration/file"
             xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
                                 http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-1.0.xsd
                                 http://www.springframework.org/schema/integration/file http://www.springframework.org/schema/integration/file/spring-integration-file-1.0.xsd
                                 http://www.springframework.org/schema/integration/mail http://www.springframework.org/schema/integration/mail/spring-integration-mail-1.0.xsd
             ">

<poller max-messages-per-poll="1" id="defaultPoller" default="true">
    <interval-trigger interval="1000"/>
</poller>


<file:inbound-channel-adapter id="filesIn"    
                              filename-pattern="ha-jdbc-cluster1.xml"
                              directory="file:/etc/****/" />


<file:outbound-channel-adapter id="filesOut" directory="classpath:/WEB-INF/classes" />

但可耻的是它不起作用。有人知道怎么做吗?

提前谢谢.....

【问题讨论】:

    标签: java xml spring spring-integration


    【解决方案1】:

    我认为问题在于目标目录。您正在使用“classpath:”前缀,它不能用于写入文件,只能用于读取。

    请告诉我们您要通过复制此路径的文件来达到什么目的,我们将尝试提出另一种方法来做同样的事情。

    【讨论】:

    • 嗨 yasha 感谢您的帖子,我在这里要做的是将配置文件从战争外部获取到战争内部,以便用户可以在外部进行配置,但是当应用程序启动时,配置将被拉到战争中,应用程序将根据它运行。如果我需要解释任何其他内容,请告诉我,感谢您的合作,我喜欢这个论坛,主要是好人。
    • 不幸的是,这种方法行不通。应用程序启动后,类加载器将看不到更新的文件。我建议将配置文件保存在不同的位置,并配置您的应用程序/网络服务器的类路径来加载它。
    【解决方案2】:

    file:inbound-file-adapter 上的目录应该可以解析为单个目录(java.io.File 实例)。不支持使用一个适配器从多个目录读取,最后我检查了...

    我会尝试将入站目录和出站目录更改为正常/众所周知的目录,例如 /tmp - /tmp/a 和 /tmp/b 中的两个目录。如果可行,那么您就知道您的配置是正常的,只是目录的值很不稳定。如果您使用 Maven 和 STS / Eclipse 或 IntelliJ,很容易调出入站通道适配器实现类并调试(FileReadingMessageSource,IIRC)它正在做什么。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-09
      • 2018-09-11
      • 2018-04-08
      • 1970-01-01
      • 1970-01-01
      • 2012-03-22
      相关资源
      最近更新 更多