2017-07-12 140 views
2

当前我正在为使用Spring集成和Spring批处理创建POC。我正在关注这个Spring Batch Integration。但我正在尝试使用注释和Spring引导来做到这一点,并且不想使用任何XML配置。任何人都可以请建议我如何从Spring批量集成中使用JobLaunchingGateway。请让我知道你是否需要更多细节。请找到我正在努力工作的下面的代码示例。使用批注的Spring集成和Spring批处理[Spring-Batch-Integration]

@Gateway(requestChannel = "outboundJobRequestChannel",replyChannel = "jobLaunchReplyChannel") 
      public JobExecution jobLauncher(Message<JobLaunchRequest> jobLaunchRequestMessage){ 
       log.info("------ Inside the Gateway ------"); 
       JobExecution jobExecution = new JobExecution(); 

       // How to use the JobLaunchingGateway here in order to launch the job 

       return jobExecution; 
      } 

回答

2

JobLaunchingGatewayMessageHandler。应该通过@ServiceActivator标注使用:

@Bean 
@ServiceActivator(inputChannel = "outboundJobRequestChannel", outputChannel = "jobLaunchReplyChannel") 
public JobLaunchingGateway jobLaunchingGateway(JobLauncher jobLauncher) { 
    return new JobLaunchingGateway(jobLauncher); 
} 

见Spring集成Reference Manual

+0

我曾尝试这一个,但得到了下面的例外,产生的原因:org.springframework.beans.BeanInstantiationException:无法实例[org.springframework.batch.integration.launch.JobLaunchingGateway]:圆形参考涉及含有豆'integrationJobConfig' - 考虑将工厂方法声明为独立于其包含实例的静态方法。工厂方法'jobLaunchingGateway'抛出异常;嵌套的异常是java.lang.NoClassDefFoundError:org/springframework/integration/MessageHandlingException – sagar27

+0

我相信有一些版本不匹配,所以我可能得到这一个。 – sagar27

+0

这的确听起来像版本不匹配。你的答案不相关。这不是在这里如何工作... –

0

JobLaunchingMessageHandler为我工作,但我也会尝试使用JobLaunchingGateway来工作。

@Bean 
@ServiceActivator(inputChannel = "outboundJobRequestChannel", outputChannel = "nullChannel") 
protected JobLaunchingMessageHandler jobLauncherHandler(JobLauncher jobLauncher) { 
    log.info("-------------- Launching the JobLauncher Request --------------"); 
    return new JobLaunchingMessageHandler(jobLauncher); 
}