Spring integration 尝试将Spring批处理与Spring集成集成时出错

Spring integration 尝试将Spring批处理与Spring集成集成时出错,spring-integration,spring-batch,Spring Integration,Spring Batch,下面的类用于轮询目录中的文件,并在收到目录中的文件后触发spring批处理。我得到了一些错误,我无法找出。请给我一些建议 此外,如果有一些示例代码示例可以执行相同的操作,请让我参考该位置 @Configuration class FilePollingIntegrationFlow { @Autowired private ApplicationContext applicationContext; // this is the integration flow t

下面的类用于轮询目录中的文件,并在收到目录中的文件后触发spring批处理。我得到了一些错误,我无法找出。请给我一些建议

此外,如果有一些示例代码示例可以执行相同的操作,请让我参考该位置

@Configuration
class FilePollingIntegrationFlow {

    @Autowired
    private ApplicationContext applicationContext;

     // this is the integration flow that foirst polls for messages and then trigger the spring batch job
    @Bean
    public IntegrationFlow inboundFileIntegration(@Value("${inbound.file.poller.fixed.delay}") long period,
                                                  @Value("${inbound.file.poller.max.messages.per.poll}") int maxMessagesPerPoll,
                                                  TaskExecutor taskExecutor,
                                                  MessageSource<File> fileReadingMessageSource,
                                                 JobLaunchingGateway jobLaunchingGateway) {



        return IntegrationFlows.from(fileReadingMessageSource,
                c -> c.poller(Pollers.fixedDelay(period)
                        .taskExecutor(taskExecutor)
                        .maxMessagesPerPoll(maxMessagesPerPoll)))
                  .transform(Transformers.fileToString())
                         .channel(ApplicationConfiguration.INBOUND_CHANNEL)                   
                  .handle((p, h) -> {
        System.out.println("Testing:::::"+p);
        return p;
 })
 .handle(fileMessageToJobRequest())
.handle(jobLaunchingGateway(),"toRequest")
 .channel(MessageChannels.queue())
                 .get();
    }

    @Bean
    public FileMessageToJobRequest fileMessageToJobRequest() {
        FileMessageToJobRequest fileMessageToJobRequest = new FileMessageToJobRequest();
        fileMessageToJobRequest.setFileParameterName("input.file.name");
      //  fileMessageToJobRequest.setJob(personJob());
        System.out.println("FilePollingIntegrationFlow::fileMessageToJobRequest::::Job launched successfully!!!");
        return fileMessageToJobRequest;
    }

    @Bean
    public JobLaunchingGateway jobLaunchingGateway() {
        SimpleJobLauncher simpleJobLauncher = new SimpleJobLauncher();
      //  simpleJobLauncher.setJobRepository(jobRepository);
        simpleJobLauncher.setTaskExecutor(new SyncTaskExecutor());
        JobLaunchingGateway jobLaunchingGateway = new JobLaunchingGateway(simpleJobLauncher);
        System.out.println("FilePollingIntegrationFlow::jobLaunchingGateway::::Job launched successfully!!!");
        return jobLaunchingGateway;
    }

//This is another class used for batch job trigger

public class FileMessageToJobRequest {
    private Job job;
    private String fileParameterName;

    public void setFileParameterName(String fileParameterName) {
        this.fileParameterName = fileParameterName;
    }

    public void setJob(Job job) {
        this.job = job;
    }

    @Transformer
    public JobLaunchRequest toRequest(Message<File> message) {
        JobParametersBuilder jobParametersBuilder =
            new JobParametersBuilder();

        jobParametersBuilder.addString(fileParameterName,
            message.getPayload().getAbsolutePath());

        return new JobLaunchRequest(job, jobParametersBuilder.toJobParameters());
    }
}
@配置
类FilePollingIntegrationFlow{
@自动连线
私有应用程序上下文应用程序上下文;
//这是一个集成流,它首先轮询消息,然后触发spring批处理作业
@豆子
public IntegrationFlow inboundFileIntegration(@Value(${inbound.file.poller.fixed.delay})长时间,
@值(${inbound.file.poller.max.messages.per.poll})int-maxMessagesPerPoll,
任务执行人任务执行人,
MessageSource文件读取MessageSource,
JobLaunchingGateway(JobLaunchingGateway){
返回IntegrationFlows.from(fileReadingMessageSource,
c->c.轮询器(轮询器固定延迟(周期)
.taskExecutor(taskExecutor)
.maxMessagesPerPoll(maxMessagesPerPoll)))
.transform(Transformers.fileToString())
.channel(应用程序配置.INBOUND_频道)
.手柄((p,h)->{
System.out.println(“测试:”+p);
返回p;
})
.handle(fileMessageToJobRequest())
.handle(jobLaunchingGateway(),“toRequest”)
.channel(MessageChannels.queue())
.get();
}
@豆子
公共文件MessageToJobRequest文件MessageToJobRequest(){
FileMessageToJobRequest FileMessageToJobRequest=新建FileMessageToJobRequest();
fileMessageToJobRequest.setFileParameterName(“input.file.name”);
//setJob(personJob());
System.out.println(“FilePollingIntegrationFlow::fileMessageToJobRequest:::作业已成功启动!!!”;
返回fileMessageToJobRequest;
}
@豆子
public JobLaunchingGateway JobLaunchingGateway(){
simplejoblancher simplejoblancher=新的simplejoblancher();
//setJobRepository(jobRepository);
setTaskExecutor(新的SyncTaskExecutor());
JobLaunchingGateway JobLaunchingGateway=新的JobLaunchingGateway(SimpleZoblancher);
System.out.println(“FilePollingIntegrationFlow::jobLaunchingGateway:::作业已成功启动!!!”;
返回作业启动网关;
}
//这是用于批处理作业触发器的另一个类
公共类FileMessageToJobRequest{
私人工作;
私有字符串fileParameterName;
public void setFileParameterName(字符串fileParameterName){
this.fileParameterName=fileParameterName;
}
公共无效设置作业(作业作业){
这个工作=工作;
}
@变压器
public Job LaunchRequest toRequest(消息){
作业参数生成器作业参数生成器=
新作业参数builder();
jobParametersBuilder.addString(fileParameterName,
message.getPayload().getAbsolutePath());
返回新的JobLaunchRequest(job,jobParametersBuilder.toJobParameters());
}
}
我得到以下错误:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'inboundFileIntegration' defined in class path resource [com/porterhead/integration/file/FilePollingIntegrationFlow.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.integration.dsl.IntegrationFlow]: Factory method 'inboundFileIntegration' threw exception; nested exception is java.lang.IllegalArgumentException: Target object of type [class org.springframework.batch.integration.launch.JobLaunchingGateway] has no eligible methods for handling Messages.
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1123)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1018)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:510)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:839)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:766)
    at org.springframework.boot.SpringApplication.createAndRefreshContext(SpringApplication.java:361)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:307)
    at org.springframework.boot.builder.SpringApplicationBuilder.run(SpringApplicationBuilder.java:134)
    at com.porterhead.Application.main(Application.java:23)
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.integration.dsl.IntegrationFlow]: Factory method 'inboundFileIntegration' threw exception; nested exception is java.lang.IllegalArgumentException: Target object of type [class org.springframework.batch.integration.launch.JobLaunchingGateway] has no eligible methods for handling Messages.
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189)
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588)
    ... 16 common frames omitted
Caused by: java.lang.IllegalArgumentException: Target object of type [class org.springframework.batch.integration.launch.JobLaunchingGateway] has no eligible methods for handling Messages.
    at org.springframework.integration.util.MessagingMethodInvokerHelper.findHandlerMethodsForTarget(MessagingMethodInvokerHelper.java:494)
    at org.springframework.integration.util.MessagingMethodInvokerHelper.<init>(MessagingMethodInvokerHelper.java:226)
    at org.springframework.integration.util.MessagingMethodInvokerHelper.<init>(MessagingMethodInvokerHelper.java:135)
    at org.springframework.integration.util.MessagingMethodInvokerHelper.<init>(MessagingMethodInvokerHelper.java:139)
    at org.springframework.integration.handler.MethodInvokingMessageProcessor.<init>(MethodInvokingMessageProcessor.java:52)
    at org.springframework.integration.handler.ServiceActivatingHandler.<init>(ServiceActivatingHandler.java:45)
    at org.springframework.integration.dsl.IntegrationFlowDefinition.handle(IntegrationFlowDefinition.java:982)
    at org.springframework.integration.dsl.IntegrationFlowDefinition.handle(IntegrationFlowDefinition.java:964)
    at com.porterhead.integration.file.FilePollingIntegrationFlow.inboundFileIntegration(FilePollingIntegrationFlow.java:85)
    at com.porterhead.integration.file.FilePollingIntegrationFlow$$EnhancerBySpringCGLIB$$c1cfa1e9.CGLIB$inboundFileIntegration$1(<generated>)
    at com.porterhead.integration.file.FilePollingIntegrationFlow$$EnhancerBySpringCGLIB$$c1cfa1e9$$FastClassBySpringCGLIB$$4ce6110e.invoke(<generated>)
    at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
    at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:356)
    at com.porterhead.integration.file.FilePollingIntegrationFlow$$EnhancerBySpringCGLIB$$c1cfa1e9.inboundFileIntegration(<generated>)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162)
    ... 17 common frames omitted
org.springframework.beans.factory.BeanCreationException:创建名为“inboundFileIntegration”的bean时出错,该bean在类路径资源[com/porterhead/integration/file/FilePollingIntegrationFlow.class]中定义:通过工厂方法实例化Bean失败;嵌套异常为org.springframework.beans.BeanInstantiationException:未能实例化[org.springframework.integration.dsl.IntegrationFlow]:工厂方法“inboundFileIntegration”引发异常;嵌套异常为java.lang.IllegalArgumentException:类型的目标对象[class org.springframework.batch.integration.launch.JobLaunchingGateway]没有处理消息的合格方法。
位于org.springframework.beans.factory.support.ConstructorResolver.InstanceUsingFactoryMethod(ConstructorResolver.java:599)
位于org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.InstanceUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1123)
位于org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1018)
位于org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:510)
位于org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
位于org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
位于org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
位于org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
位于org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
位于org.springframework.beans.factory.support.DefaultListableBeanFactory.PreInstanceSingleton(DefaultListableBeanFactory.java:772)
位于org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:839)
位于org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538)
位于org.springframework.boot.SpringApplication.refresh(SpringApplication.java:766)
位于org.springframework.boot.SpringApplication.createAndRefreshContext(SpringApplication.java:361)
位于org.springframework.boot.SpringApplication.run(SpringApplication.java:307)
在org.springframework上
.transform(fileMessageToJobRequest())
.handle(jobLaunchingGateway())