如何解决根据当前日期的 Spring SFTP 过滤器文件名
我想用 Spring SFTP 适配器读取文件。该文件(名称:“myFile_20210510.csv”)每天在 SFTP 上创建。 代码如下:
@Bean
@InboundChannelAdapter(channel = "stream",poller = @Poller(fixedDelay = "1000"))
public MessageSource<InputStream> ftpMessageSource() {
SftpStreamingMessageSource messageSource = new SftpStreamingMessageSource(template());
messageSource.setRemoteDirectory(sftpDirectory);
messageSource.setLoggingEnabled(true);
messageSource.setFilter(new SftpRegexPatternFileListFilter(".*myFile_"
+ LocalDate.now().format(DateTimeFormatter.ofPattern("yyyyMMdd")).toString() + "\\.csv$"));
return messageSource;
}
到目前为止,这是有效的。如果我启动应用程序并将文件复制到 SFTP,它会被读取。 问题是,根据 Spring SFTP varying filename-regex 过滤器被设置为一个运行时对象,所以过滤器在我启动应用程序的那天是固定的,并且不会每天更新。最后,只有在我重新启动应用程序后才能读取文件。
那么,我该如何设置过滤器,才能实现每天正确设置日期?
感谢您的帮助。
您好, 菲尔
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。