Spring SFTP根据当前日期筛选文件名
我想读一个带有Spring SFTP适配器的文件。该文件(名称:“myFile_20210510.csv”)每天在SFTP上创建。 代码如下:Spring SFTP根据当前日期筛选文件名,spring,filter,sftp,Spring,Filter,Sftp,我想读一个带有Spring SFTP适配器的文件。该文件(名称:“myFile_20210510.csv”)每天在SFTP上创建。 代码如下: @Bean @InboundChannelAdapter(channel = "stream", poller = @Poller(fixedDelay = "1000")) public MessageSource<InputStream> ftpMessageSource() {
@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;
}
@Bean
@InboundChannelAdapter(channel=“stream”,poller=@poller(fixedDelay=“1000”))
public MessageSource ftpMessageSource(){
SftpStreamingMessageSource messageSource=新的SftpStreamingMessageSource(模板());
setRemoteDirectory(sftpDirectory);
messageSource.setLoggingEnabled(true);
messageSource.setFilter(新的sftpregaternFileListFilter(“.*myFile_382;”
+LocalDate.now().format(DateTimeFormatter.of模式(“yyyyMMdd”)).toString()+“\\.csv$”);
返回消息源;
}
到目前为止,这是有效的。如果我启动应用程序并将文件复制到SFTP中,它就会被读取。
问题是,根据
过滤器被设置为一个运行时对象,因此过滤器在我启动应用程序的那一天是固定的,不会每天更新。最后,只有在我重新启动应用程序后,文件才会被读取
那么,我该如何设置过滤器,以实现每天正确设置日期
谢谢你的帮助
您好,
菲尔