You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Spring Integration SMB集成问题:Windows共享驱动器未扫描子目录

问题原因及解决方案

核心问题

你配置的SmbRegexPatternFileListFilter正则表达式(.*/)*.*无法匹配Windows共享目录中子文件的路径格式:

  • Windows共享使用**反斜杠()**作为路径分隔符,而你的正则用的是正斜杠(/)
  • SmbRegexPatternFileListFilter会基于文件的完整相对路径(如subdir\file4.txt)匹配,你的正则无法识别反斜杠分隔的子目录路径,导致子目录下的文件被过滤器拦截。
  • 此外该正则本身冗余——你需要同步所有文件,没必要用正则过滤,反而画蛇添足。

修复方案

方案1:移除冗余过滤器(推荐)

直接使用默认的AcceptAllFileListFilter即可,保留递归扫描配置:

@Bean
public IntegrationFlow smbInboundFlow() {
    RecursiveDirectoryScanner scanner = new RecursiveDirectoryScanner();
    scanner.setMaxDepth(5);
    return IntegrationFlow
            .from(Smb.inboundAdapter(smbSessionFactory())
                            .preserveTimestamp(true)
                            .remoteDirectory("./")
                            .scanner(scanner)
                            .localDirectory(new File("./tmp/copyfolder")),
                    e -> e.id("smbInboundAdapter")
                            .autoStartup(true)
                            .poller(Pollers.fixedDelay(400)))
            .handle(m -> {
                System.out.println(m.getPayload());
            })
            .get();
}

方案2:修正正则表达式(若需保留过滤逻辑)

如果必须使用正则过滤,修改正则兼容Windows反斜杠路径:

@Bean
public IntegrationFlow smbInboundFlow() {
    RecursiveDirectoryScanner scanner = new RecursiveDirectoryScanner();
    // 兼容正斜杠和反斜杠,匹配所有文件
    ChainFileListFilter filter = new ChainFileListFilter<>(
            Arrays.asList(new SmbRegexPatternFileListFilter("(.*/|.*\\\\)*.*")));
    scanner.setFilter(filter);
    scanner.setMaxDepth(5);
    return IntegrationFlow
            .from(Smb.inboundAdapter(smbSessionFactory())
                            .preserveTimestamp(true)
                            .remoteDirectory("./")
                            .scanner(scanner)
                            .localDirectory(new File("./tmp/copyfolder")),
                    e -> e.id("smbInboundAdapter")
                            .autoStartup(true)
                            .poller(Pollers.fixedDelay(400)))
            .handle(m -> {
                System.out.println(m.getPayload());
            })
            .get();
}

额外验证点

  • 确认smbSessionFactory配置正确,拥有远程共享目录及子目录的读写权限
  • 检查本地目录./tmp/copyfolder的读写权限,确保应用可创建子目录并写入文件

内容的提问来源于stack exchange,提问作者siva

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.13 13:05:09