首页 > 解决方案 > 日志被 WARN 消息污染:“使用递归时文件名模式必须为 '*'”

问题描述

我在 Spring Boot 应用程序中使用 Spring Integration(版本 5.4.4)从 sftp 服务器递归下载文件。为此,我使用带有 mget 命令和正则表达式文件名过滤器的 SFTP 出站网关:

@Bean
public IntegrationFlow jsonFilesReadingFlow() {
    String JSON_FILE_REGEX = "...";
    return IntegrationFlows
            .from("sftp_server")
            .handle(Sftp
                    .outboundGateway(sftpSessionFactory(), Command.MGET, "payload")
                    .options(Option.RECURSIVE)
                    .regexFileNameFilter(JSON_FILE_REGEX)
                    .filter(new SftpPersistentAcceptOnceFileListFilter(new SimpleMetadataStore(), "Downloaded_json_file:"))
                    .autoCreateLocalDirectory(true)
                    .localDirectoryExpression("'/${catalina.base}/webapps/app/WEB-INF/classes/temporaryJsonFilesDirectory'")
                    .localFilenameExpression("#remoteFileName.replaceFirst('sftpSource', 'localTarget')"))
            .channel("downloadJsonFileOutputChannel")
            .get();
}

不幸的是,每次在应用程序日志中检查 sftp 服务器时,都会创建一个条目:“[WARN] 2021-07-06 08:56:21 [scheduling-1] org.springframework.core.log.LogAccessor - 文件名使用递归时模式必须是'*'"

屏幕截图 - 应用程序日志

不幸的是,我无法解决这个问题 - 你有什么想法吗?

标签: recursionspring-integrationspring-integration-sftp

解决方案


远程文件路径的表达式(payload在您的情况下)必须评估为应该以 . 结尾的内容*,例如remoteDir/*. 必须传输树中的所有文件名。只有在那之后,您的文件列表过滤器才会产生影响。

请参阅文档中的注释:https ://docs.spring.io/spring-integration/docs/current/reference/html/sftp.html#using-the-mget-command


推荐阅读