I need to implement two different jobs, and choose which one of them I want to run, but I currently can't, it is giving me the following error:
Field processJob in JobInvokerController required a single bean, but 2 were found:
- procesaClientesJob: defined by method 'procesaClientesJob' in class path resource [BatchConfig.class]
- procesaParcialClientesJob: defined by method 'procesaParcialClientesJob' in class path resource [BatchConfig.class]
Action:
Consider marking one of the beans as @Primary, updating the consumer to accept multiple beans, or using @Qualifier to identify the bean that should be consumed
My BatchConfig.java is like:
[....]
@Bean
Job procesaClientesJob(JobBuilderFactory jobBuilderFactory,
@Qualifier("flowCargaIdsClientes") Flow flowCargaIdsClientes,
@Qualifier("flowCargaDatosClientes") Flow flowCargaDatosClientes,
@Qualifier("flowCargaParcialIdsClientes") Flow flowCargaParcialIdsClientes,
@Qualifier("flowCargaParcialDatosClientes") Flow flowCargaParcialDatosClientes
) {
return jobBuilderFactory.get("procesaClientesJob")
.incrementer(new RunIdIncrementer())
.start(flowCargaIdsClientes).next(flowCargaDatosClientes).end()
.build();
}
@Bean
Job procesaParcialClientesJob(JobBuilderFactory jobBuilderFactory,
@Qualifier("flowCargaParcialIdsClientes") Flow flowCargaParcialIdsClientes,
@Qualifier("flowCargaParcialDatosClientes") Flow flowCargaParcialDatosClientes
) {
return jobBuilderFactory.get("procesaClientesJob")
.incrementer(new RunIdIncrementer())
.start(flowCargaParcialIdsClientes).next(flowCargaParcialDatosClientes).end()
.build();
}
My class JobInvokeController.java is like:
@RestController
public class JobInvokerController {
private static final Logger log = Logger.getLogger(JobInvokerController.class);
@Autowired
JobLauncher jobLauncher;
@Autowired
Job processJob;
@GetMapping("/invokejob/{strFecha}")
public String invokejob(@PathVariable String strFecha) throws Exception {
Date fecha;
if (log.isDebugEnabled()) {
log.debug("Procesamos el parámetro de entrada " + strFecha);
}
try {
if (!StringUtils.isEmpty(strFecha)) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
fecha = sdf.parse(strFecha);
} else {
fecha = new Date();
}
} catch (Exception e) {
fecha = new Date();
}
if (log.isDebugEnabled()) {
log.debug("Invocamos al batch con la fecha: " + fecha);
}
JobParameters jobParameters = new JobParametersBuilder().addLong("time",System.currentTimeMillis()).addDate("fecha", fecha).toJobParameters();
jobLauncher.run(processJob, jobParameters);
return "Batch job has been invoked";
}
}
And I also have a SpringBatchApplication.java:
@SpringBootApplication
public class SpringBatchApplication {
public static void main(String[] args) {
SpringApplication.run(SpringBatchApplication.class, args);
}
}
How can I have two simultaneous jobs and choose what I want to run?