使用spring集成复制文件

时间:2011-02-04 13:57:41

标签: java xml spring spring-integration

如何使用spring集成将文件从一个地方复制到另一个地方。在我的情况下,我想将战争之外的文件复制到战争中。这是我正在考虑的代码片段:

<?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" />

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

提前感谢.....

2 个答案:

答案 0 :(得分:1)

我认为该问题与目标目录有关。您正在使用“classpath:”前缀,该前缀不能用于将文件写入,只能从中读取。

请通过复制此路径的文件告诉我们您要实现的目标,我们将尝试采用其他方法来实现相同目标。

答案 1 :(得分:0)

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

我会尝试将入站目录和出站目录更改为/ tmp - / tmp / a和/ tmp / b中的两个目录。如果有效,那么你知道你的配置是理智的,只是目录的值是不可思议的。如果你使用Maven和STS / Eclipse或IntelliJ,它很容易调出入站通道适配器实现类和调试(FileReadingMessageSource,IIRC)到它正在做的事情。