我有 Spring 集成管道,它从 SFTP 服务器获取文档并将其保存到 Postgresql 数据库(由 Spring data/hibernate 完成)。成功 sftp 获取管道后,获取文件名和内容(作为 byte[])并将其保存到数据库。
我有两个主要问题:
问题是我没有预料到客户端会上传 100Mb - 200MB 的 zip 文件,管道可以读取但无法持久保存。
有时会抛出(并非总是)“java.lang.OutOfMemoryError:Java堆空间”, 但增加的堆内存暂时解决了这个问题,也许有 不需要将整个文件内容加载到内存的解决方案 在持久化到数据库之前?
仅记录事务期间记录的消息:
"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."}
我知道我应该共享代码,但实际上不能(法律问题)。
最佳答案
考虑使用 Sftp Streaming MessageSource
而不是在本地文件系统上复制/粘贴:https://docs.spring.io/spring-integration/docs/current/reference/html/#sftp-streaming
关于java - 使用 Spring 和 Hibernate 从 SFTP 获取大文件并存储在 Postgresql 中的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56150577/