首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >使用spring集成从SFTP服务器读取excel文件时出现问题

使用spring集成从SFTP服务器读取excel文件时出现问题
EN

Stack Overflow用户
提问于 2019-03-05 07:35:31
回答 2查看 691关注 0票数 -2

我是Spring集成的新手,所以它对专家来说可能是愚蠢的。

我想每天早上在SFTP服务器上读取一个excel文件(目前我设置为每分钟读取一次,如下所示)。我已经写了所有的代码,收到的excel的输入流和使用POI遍历它。

如果我给文件手动从JSP上传,那么没有问题,一切都很好。

但是当我使用下面的代码启用spring集成时,它会给我错误。

我发现"DefaultSftpSessionFactory“对"jsch-0.1.51.jar”有内在的依赖关系,这也是我手工绑定的一部分。

https://docs.spring.io/spring-integration/api/org/springframework/integration/sftp/session/DefaultSftpSessionFactory.html

我使用的是spring 4.0.9。

仅供参考,控件在我的"processFTPFile“方法之前是不会出现的。

    <bean id="ultiProSftpSessionFactory" class="org.springframework.integration.sftp.session.DefaultSftpSessionFactory">
        <property name="host" value="serverhost" />
        <property name="user" value="user" />
        <property name="password" value="password" />

    </bean>

    <int-ftp:inbound-channel-adapter id="ftpInboundChannelAdapter" session-factory="ultiProSftpSessionFactory" channel="fileAvailableChannel" 
            filename-pattern="* Consolidated Report.xlsx"
            remote-directory="/folder1/folder2"
            preserve-timestamp="true"
            local-directory="."
            auto-create-local-directory="true"
            delete-remote-files="false"
            auto-startup="true">
            <int:poller cron="0 0/1 * * * *">
            </int:poller>
    </int-ftp:inbound-channel-adapter>

    <int:service-activator id="serviceUpdateTrackingItem" method="processFTPFile" ref="cAPunchDataAdapter" input-channel="fileAvailableChannel" />

    <int:publish-subscribe-channel id="fileAvailableChannel"/>

我想在每个文件上执行的代码

    @Component("cAPunchDataAdapter")
    public class CAPunchDataAdapter {


        public void processFTPFile(FTPFile file) {

            //Code goes here to get inputstream of file.


        }

    }

下面是错误日志。

    [3/4/19 18:20:00:731 EST] 00002560 SystemErr     R [ERROR] LoggingHandler - -org.springframework.messaging.MessagingException: Problem occurred while synchronizing remote to local directory
        at org.springframework.integration.file.remote.synchronizer.AbstractInboundFileSynchronizer.synchronizeToLocalDirectory(AbstractInboundFileSynchronizer.java:209)
        at org.springframework.integration.file.remote.synchronizer.AbstractInboundFileSynchronizingMessageSource.receive(AbstractInboundFileSynchronizingMessageSource.java:167)
        at org.springframework.integration.endpoint.SourcePollingChannelAdapter.receiveMessage(SourcePollingChannelAdapter.java:144)
        at org.springframework.integration.endpoint.AbstractPollingEndpoint.doPoll(AbstractPollingEndpoint.java:192)
        at org.springframework.integration.endpoint.AbstractPollingEndpoint.access$000(AbstractPollingEndpoint.java:55)
        at org.springframework.integration.endpoint.AbstractPollingEndpoint$1.call(AbstractPollingEndpoint.java:149)
        at org.springframework.integration.endpoint.AbstractPollingEndpoint$1.call(AbstractPollingEndpoint.java:146)
        at org.springframework.integration.endpoint.AbstractPollingEndpoint$Poller$1.run(AbstractPollingEndpoint.java:298)
        at org.springframework.integration.util.ErrorHandlingTaskExecutor$1.run(ErrorHandlingTaskExecutor.java:52)
        at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:50)
        at org.springframework.integration.util.ErrorHandlingTaskExecutor.execute(ErrorHandlingTaskExecutor.java:49)
        at org.springframework.integration.endpoint.AbstractPollingEndpoint$Poller.run(AbstractPollingEndpoint.java:292)
        at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54)
        at org.springframework.scheduling.concurrent.ReschedulingRunnable.run(ReschedulingRunnable.java:81)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:522)
        at java.util.concurrent.FutureTask.run(FutureTask.java:277)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:191)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1153)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
        at java.lang.Thread.run(Thread.java:785)
    Caused by: org.springframework.messaging.MessagingException: Failed to execute on session
        at org.springframework.integration.file.remote.RemoteFileTemplate.execute(RemoteFileTemplate.java:321)
        at org.springframework.integration.file.remote.synchronizer.AbstractInboundFileSynchronizer.synchronizeToLocalDirectory(AbstractInboundFileSynchronizer.java:167)
        ... 20 more
    Caused by: java.lang.ClassCastException: com.jcraft.jsch.ChannelSftp$LsEntry incompatible with org.apache.commons.net.ftp.FTPFile
        at org.springframework.integration.ftp.filters.FtpSimplePatternFileListFilter.getFilename(FtpSimplePatternFileListFilter.java:29)
        at org.springframework.integration.file.filters.AbstractSimplePatternFileListFilter.accept(AbstractSimplePatternFileListFilter.java:49)
        at org.springframework.integration.file.filters.AbstractFileListFilter.filterFiles(AbstractFileListFilter.java:40)
        at org.springframework.integration.file.remote.synchronizer.AbstractInboundFileSynchronizer.filterFiles(AbstractInboundFileSynchronizer.java:157)
        at org.springframework.integration.file.remote.synchronizer.AbstractInboundFileSynchronizer$1.doInSession(AbstractInboundFileSynchronizer.java:173)
        at org.springframework.integration.file.remote.synchronizer.AbstractInboundFileSynchronizer$1.doInSession(AbstractInboundFileSynchronizer.java:167)
        at org.springframework.integration.file.remote.RemoteFileTemplate.execute(RemoteFileTemplate.java:312)
        ... 21 more
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2019-03-05 09:40:14

JSch是用于ftp的,您正在使用ftp

你需要

<int-sftp:inbound-channel-adapter id="ftpInboundChannelAdapter" session-factory="ultiProSftpSessionFactory" channel="fileAvailableCh

(int-sftp:,而不是int-ftp:)

票数 1
EN

Stack Overflow用户

发布于 2019-03-05 09:40:17

找到了修复方法,我就没想到会这样了。

已替换

<int-ftp:inbound-channel-adapter

使用

<int-sftp:inbound-channel-adapter

Spring应该实现更好的错误消息:)。

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54993247

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档