I'm very new to Spring Batch and pretty confused
I've got a controller with some request mappings. When I get a certain URL I want to print the job status to the response body. Here's some code:
@RequestMapping(value = "/batchExecution", method = RequestMethod.GET)
@ResponseBody
public String getJobExecutionStatus() {
return "Hello world!";
}
I've tried adding JobExecution to the method, but can you only access these elements with the JobExecutionListener?
@RequestMapping(value = "/batchExecution", method = RequestMethod.GET)
@ResponseBody
public String getJobExecutionStatus(JobExecution jobExecution) {
return "Hello world!";
}
sorry for my noobie questions, I can't find any documentation on what I'm looking for
To resolve this issue I was able to answer my own question with the help of Pospolita Nikita's comments on my original post.
I implemented a service with a process method, and then called that method in my program controller. The code looks like this:
Service
@Override
public String process(Long jobId) throws Exception {
BatchStatus jobStatus = explorer.getJobExecution(jobId).getStatus();
LOGGER.info("The Job ID is: " + jobId);
LOGGER.info("The job status is: "+jobStatus);
return null;
}
Controller
@RequestMapping(value = "/batchMonitor/{id}", method = RequestMethod.GET)
@ResponseBody
public ResponseEntity<String> process(@PathVariable("id") Long id) {
HttpHeaders responseHeaders = MccControllerUtils.createCacheDisabledHeaders();
responseHeaders.setContentType(MediaType.TEXT_HTML);
try {
LOGGER.info("Obtaining job by ID " + id);
String response = batchService.process(id);
return new ResponseEntity<>(response, responseHeaders, HttpStatus.OK);
} catch (Exception e) {
LOGGER.error("Error obtaining batch by ID " + id, e);
return new ResponseEntity<>(e.getMessage(), responseHeaders, HttpStatus.INTERNAL_SERVER_ERROR);
}
}
Hopefully this can help someone else down the road. Thanks!
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加