Spring boot Spring批处理集成:java.lang.ClassCastException:org.springframework.integration.file.FileReadingMessageSource无法强制转换为java.io.file @InboundChannelAdapter(value=“fileInputChannel”,poller=@poller(fixedDelay=“15000”)) public MessageSource fileReadingMessageSource(){ FileReadingMessageSource=新建FileReadingMessageSource(); setDirectory(新文件(ftpUploadDir)); setFilter(新的SimplePatternFileListFilter(“*.csv”); 来源:setScanEachPoll(真); source.setUseWatchService(true); 返回源; } @转换器(inputChannel=“fileInputChannel”,outputChannel=“jobChannel”) public JobLaunchRequest转换(消息文件){ log.info(文件.getPayload().toString()); JobParameters JobParameters=新的JobParametersBuilder() .addString(“文件名”,file.getPayload().getAbsolutePath()) .addDate(“日期时间”,新日期()) .toJobParameters(); JobLaunchRequest=新JobLaunchRequest(作业,作业参数); 返回请求; }
您还需要将Spring boot Spring批处理集成:java.lang.ClassCastException:org.springframework.integration.file.FileReadingMessageSource无法强制转换为java.io.file @InboundChannelAdapter(value=“fileInputChannel”,poller=@poller(fixedDelay=“15000”)) public MessageSource fileReadingMessageSource(){ FileReadingMessageSource=新建FileReadingMessageSource(); setDirectory(新文件(ftpUploadDir)); setFilter(新的SimplePatternFileListFilter(“*.csv”); 来源:setScanEachPoll(真); source.setUseWatchService(true); 返回源; } @转换器(inputChannel=“fileInputChannel”,outputChannel=“jobChannel”) public JobLaunchRequest转换(消息文件){ log.info(文件.getPayload().toString()); JobParameters JobParameters=新的JobParametersBuilder() .addString(“文件名”,file.getPayload().getAbsolutePath()) .addDate(“日期时间”,新日期()) .toJobParameters(); JobLaunchRequest=新JobLaunchRequest(作业,作业参数); 返回请求; },spring-boot,spring-integration,spring-batch,Spring Boot,Spring Integration,Spring Batch,您还需要将@Bean注释与@InboundChannelAdapter一起添加到fileReadingMessageSource()方法中 要点是,如果没有@Bean,框架将基于此fileReadingMessageSource()方法调用的结果,使用MethodInvokingMessageSource创建一个SourcePollingChannelAdapter 有关更多信息,请参阅Spring集成参考手册:您还需要将@Bean注释与@InboundChannelAdapter一起添加到fi
@Bean
注释与@InboundChannelAdapter
一起添加到fileReadingMessageSource()
方法中
要点是,如果没有@Bean
,框架将基于此fileReadingMessageSource()
方法调用的结果,使用MethodInvokingMessageSource
创建一个SourcePollingChannelAdapter
有关更多信息,请参阅Spring集成参考手册:您还需要将
@Bean
注释与@InboundChannelAdapter
一起添加到fileReadingMessageSource()
方法中
要点是,如果没有@Bean
,框架将基于此fileReadingMessageSource()
方法调用的结果,使用MethodInvokingMessageSource
创建一个SourcePollingChannelAdapter
有关更多信息,请参阅Spring集成参考手册:欢迎使用Stack Overflow!为了帮助其他人理解并回答你的问题,请你回答:1。明确说明你的目标和你面临的问题。显示错误发生的确切时间,并提供堆栈跟踪3。适当格式化代码请提供更多上下文以帮助您。请参阅我的答案。欢迎使用堆栈溢出!为了帮助其他人理解并回答你的问题,请你回答:1。明确说明你的目标和你面临的问题。显示错误发生的确切时间,并提供堆栈跟踪3。适当地格式化代码请提供更多的上下文以帮助您。请参阅我的答案。谢谢。我现在有点困了。我在调试模式下运行应用程序。我可以看到控件正在进入FileReadingMessageSourcebean,控件没有进入FileToJobTransformer的转换方法。谢谢你。我现在有点困了。我在调试模式下运行应用程序。我可以看到控件正在进入FileReadingMessageSourcebean,控件没有进入FileToJobTransformer的转换方法。
@InboundChannelAdapter(value = "fileInputChannel", poller = @Poller(fixedDelay = "15000"))
public MessageSource<File> fileReadingMessageSource() {
FileReadingMessageSource source = new FileReadingMessageSource();
source.setDirectory(new File(ftpUploadDir));
source.setFilter(new SimplePatternFileListFilter("*.csv"));
source.setScanEachPoll(true);
source.setUseWatchService(true);
return source;
}
@Transformer(inputChannel = "fileInputChannel", outputChannel = "jobChannel")
public JobLaunchRequest transform(Message<File> file) {
log.info( file.getPayload().toString());
JobParameters jobParameters = new JobParametersBuilder()
.addString("fileName", file.getPayload().getAbsolutePath())
.addDate("dateTime", new Date())
.toJobParameters();
JobLaunchRequest request = new JobLaunchRequest(job, jobParameters);
return request;
}