简体   繁体   中英

How to invoke Spring Batch Jobs embedded in a Spring Boot Application using CommandLineJobRunner

I have a spring boot application which has 2 modules to it. First is a web module that exposes a rest API which allows users to some data into the application. Second module is set of batch jobs that act on these configurations and perform background processing.

I was able to create both REST API and batch jobs in the application and as a starting point, I used a REST end point to kickoff my batch jobs using JobLauncher.

My next task is to package the application and deploy the web application to expose REST endpoints and also create shell scripts to kick off the batch jobs using an enterprise scheduler.

I am Using Maven and spring-boot-maven-plugin to build the executable jar. When I execute java -jar myApp.jar REST APIs are getting exposed however, when I try to run the batch jobs by executing java -cp myApp.jar org.springframework.batch.core.launch.support.CommandLineJobRunner com.example.myJobConfig job1 runDate=2020-02-29

I get the following error Error: Could not find or load main class org.springframework.batch.core.launch.support.CommandLineJobRunner

I am looking for help on how I can have both web app and batch jobs in a single application and launch the batch jobs using a shell script.

I am Using Maven and spring-boot-maven-plugin to build the executable jar

In this case, you can run your job on the command line using:

java -jar myApp.jar --spring.batch.job.names=job1 runDate=2020-02-29

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM