spring - Spring SFTP过滤文件名根据当前日期
问题描述
我想用 Spring SFTP Adapters 读取文件。该文件(名称:“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 不同的文件名正则表达式 ,过滤器被设置为运行时对象,因此过滤器在我启动应用程序的那天固定,并且不会每天更新。最后,只有在我重新启动应用程序后才能读取文件。
那么,我该如何设置过滤器,以实现每天正确设置日期呢?
谢谢您的帮助。
问候,菲尔
解决方案
推荐阅读
- python - Linux 不支持使用 pyodbc 和 CODEPAGE 的转换错误
- c - 如何通过 UDP 发送结构并在另一端接收?
- c# - 有没有一种简单的方法可以从数据库中获取特定的列数据
- javascript - 这两种制作二维矩阵的方法有什么区别?
- python - 无法在 CentOS 7 中安装 mysqlclient
- keycloak - httpd反向代理配置背后的keycloak和guacamole配置
- asp.net-mvc - 不支持关键字:'port' - NpgSql
- rxjs - 如何在 rxjs 中的重复操作之间添加延迟
- python - 如何在我的 TKinter 应用程序中使 matplotlib 折线图具有交互性?
- youtube-api - 来自 YouTube 数据 API 的 PlaylistItems.list 的响应不一致且无效