2727import org .apache .commons .logging .LogFactory ;
2828
2929import org .springframework .batch .core .BatchStatus ;
30- import org .springframework .batch .core .Job ;
31- import org .springframework .batch .core .JobExecution ;
32- import org .springframework .batch .core .JobExecutionException ;
33- import org .springframework .batch .core .JobParameter ;
34- import org .springframework .batch .core .JobParameters ;
35- import org .springframework .batch .core .JobParametersBuilder ;
36- import org .springframework .batch .core .JobParametersInvalidException ;
3730import org .springframework .batch .core .configuration .JobRegistry ;
3831import org .springframework .batch .core .converter .DefaultJobParametersConverter ;
3932import org .springframework .batch .core .converter .JobParametersConverter ;
40- import org .springframework .batch .core .explore .JobExplorer ;
41- import org .springframework .batch .core .launch .JobLauncher ;
33+ import org .springframework .batch .core .job .Job ;
34+ import org .springframework .batch .core .job .JobExecution ;
35+ import org .springframework .batch .core .job .JobExecutionException ;
36+ import org .springframework .batch .core .job .parameters .JobParameter ;
37+ import org .springframework .batch .core .job .parameters .JobParameters ;
38+ import org .springframework .batch .core .job .parameters .JobParametersBuilder ;
39+ import org .springframework .batch .core .job .parameters .JobParametersInvalidException ;
40+ import org .springframework .batch .core .launch .JobOperator ;
41+ import org .springframework .batch .core .launch .NoSuchJobException ;
4242import org .springframework .batch .core .repository .JobExecutionAlreadyRunningException ;
4343import org .springframework .batch .core .repository .JobInstanceAlreadyCompleteException ;
4444import org .springframework .batch .core .repository .JobRepository ;
5555import org .springframework .util .StringUtils ;
5656
5757/**
58- * {@link ApplicationRunner} to {@link JobLauncher launch} Spring Batch jobs. If a single
58+ * {@link ApplicationRunner} to {@link JobOperator launch} Spring Batch jobs. If a single
5959 * job is found in the context, it will be executed by default. If multiple jobs are
6060 * found, launch a specific job by providing a jobName.
6161 *
@@ -78,9 +78,7 @@ public class JobLauncherApplicationRunner
7878
7979 private JobParametersConverter converter = new DefaultJobParametersConverter ();
8080
81- private final JobLauncher jobLauncher ;
82-
83- private final JobExplorer jobExplorer ;
81+ private final JobOperator jobOperator ;
8482
8583 private final JobRepository jobRepository ;
8684
@@ -96,17 +94,14 @@ public class JobLauncherApplicationRunner
9694
9795 /**
9896 * Create a new {@link JobLauncherApplicationRunner}.
99- * @param jobLauncher to launch jobs
100- * @param jobExplorer to check the job repository for previous executions
97+ * @param jobOperator to launch jobs
10198 * @param jobRepository to check if a job instance exists with the given parameters
10299 * when running a job
103100 */
104- public JobLauncherApplicationRunner (JobLauncher jobLauncher , JobExplorer jobExplorer , JobRepository jobRepository ) {
105- Assert .notNull (jobLauncher , "'jobLauncher' must not be null" );
106- Assert .notNull (jobExplorer , "'jobExplorer' must not be null" );
101+ public JobLauncherApplicationRunner (JobOperator jobOperator , JobRepository jobRepository ) {
102+ Assert .notNull (jobOperator , "'jobOperator' must not be null" );
107103 Assert .notNull (jobRepository , "'jobRepository' must not be null" );
108- this .jobLauncher = jobLauncher ;
109- this .jobExplorer = jobExplorer ;
104+ this .jobOperator = jobOperator ;
110105 this .jobRepository = jobRepository ;
111106 }
112107
@@ -199,23 +194,24 @@ private void executeRegisteredJobs(JobParameters jobParameters) throws JobExecut
199194 }
200195 }
201196
202- protected void execute (Job job , JobParameters jobParameters ) throws JobExecutionAlreadyRunningException ,
203- JobRestartException , JobInstanceAlreadyCompleteException , JobParametersInvalidException {
197+ protected void execute (Job job , JobParameters jobParameters )
198+ throws JobExecutionAlreadyRunningException , NoSuchJobException , JobRestartException ,
199+ JobInstanceAlreadyCompleteException , JobParametersInvalidException {
204200 JobParameters parameters = getNextJobParameters (job , jobParameters );
205- JobExecution execution = this .jobLauncher . run (job , parameters );
201+ JobExecution execution = this .jobOperator . start (job , parameters );
206202 if (this .publisher != null ) {
207203 this .publisher .publishEvent (new JobExecutionEvent (execution ));
208204 }
209205 }
210206
211207 private JobParameters getNextJobParameters (Job job , JobParameters jobParameters ) {
212- if (this .jobRepository != null && this .jobRepository .isJobInstanceExists (job .getName (), jobParameters )) {
208+ if (this .jobRepository != null && this .jobRepository .getJobInstance (job .getName (), jobParameters ) != null ) {
213209 return getNextJobParametersForExisting (job , jobParameters );
214210 }
215211 if (job .getJobParametersIncrementer () == null ) {
216212 return jobParameters ;
217213 }
218- JobParameters nextParameters = new JobParametersBuilder (jobParameters , this .jobExplorer )
214+ JobParameters nextParameters = new JobParametersBuilder (jobParameters , this .jobRepository )
219215 .getNextJobParameters (job )
220216 .toJobParameters ();
221217 return merge (nextParameters , jobParameters );
0 commit comments