使用 Spring 和 Hibernate 从 SFTP 获取大文件并存储在

我有 Spring 集成管道,它从 SFTP 服务器获取文档并将其保存到 Postgresql 数据库(由 Spring data/hibernate 完成)。成功后 sftp 获取管道获取文件名和内容(如 byte[])并将其保存到数据库。

我有两个主要问题:

  1. 问题是我没有预料到客户端会上传 100Mb - 200MB 的 zip 文件,管道读取但无法持久保存。

  2. 有时(不总是)抛出“java.lang.OutOfMemoryError:Java heap space”,但增加的堆内存暂时解决了这个问题,也许有解决方案不需要在持久保存到数据库之前将整个文件内容加载到内存?

仅记录事务期间记录的消息:

"thread":"task-scheduler-8","location":"org.springframework.integration.file.remote.synchronizer.AbstractInboundFileSynchronizer.copyFileToLocalDirectory(AbstractInboundFileSynchronizer.java:430)","level":"WARN","message":"The remote file '-r-x------ 1 0        0           81062125 May 15 15:06 test.zip' has not been transferred to the existing local file './transfered-files/test.zip'. Consider removing the local file."}

我明白我应该分享代码,但真的不能(法律问题)。


翻过高山走不出你
浏览 122回答 1
1回答

PIPIONE

考虑SftpStreamingMessageSource在本地文件系统上使用不复制/粘贴:https ://docs.spring.io/spring-integration/docs/current/reference/html/#sftp-streaming
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java