简体   繁体   中英

copy file using spring integration

how would you copy a file from one place to another using spring integration. in my case i want to copy a file outside the war to inside the war. here is the code snippet i am thinking about:

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

but shamefully it does not work. does anyone know how to do it?

thanks in advance .....

I think that issue is with target directory. You're using "classpath:" prefix which can't be used to write files to, only to read from.

Please let us know what you're trying to achieve by copying file for this path and we will try to come up with another approach to do same.

the directory on the file:inbound-file-adapter should be something that can resolves to a single directory (a java.io.File instance). There's no support for reading from multiple directories with one adapter, last I checked...

I'd try changing the directory on the inbound and the directory on the outbound to something sane / well known like two directories in /tmp - /tmp/a and /tmp/b. if that works, then you know your configuration is sane, just the values for the directories are wonky. If youre using Maven and either STS / Eclipse or IntelliJ, its easy to bring up the inbound channel adapter implementation class and debug (FileReadingMessageSource, IIRC) to what it's doing.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM