2017-07-17 175 views
1

是否有任何方式指定Scheduler for特定的Spring批處理作業配置通過XML沒有utils RunScheduler類是這樣的:https://www.mkyong.com/spring-batch/spring-batch-and-spring-taskscheduler-example/Spring批處理Job Scheduler

所以現在我的配置是這樣的:

<batch:job id="testJob" job-repository="jobRepository" parent="jobParent"> 
     <batch:step id="testStep" allow-start-if-complete="true"> 
      <batch:tasklet> 
       <batch:chunk 
         reader="testReader" 
         processor="testProcessor" 
         writer="jmsWriter"> 
       </batch:chunk> 
      </batch:tasklet> 
     </batch:step> 
    </batch:job> 


<task:scheduled-tasks> 
     <task:scheduled ref="testJobLauncher" method="runJob" cron="0 */5 * * * *"/> 
    </task:scheduled-tasks> 

    <bean id="testJobLauncher" 
      class="com.test.RunScheduler" 
      p:job-ref="testJob" 
      p:jobLauncher-ref="jobLauncher" 
    "/> 



@Component 
public class RunScheduler { 

    private JobLauncher jobLauncher; 
    private Job job; 

    public void runJob() { 
     try { 
      String dateParam = new Date().toString(); 
       JobParameters param = new JobParametersBuilder().addString("date", dateParam).toJobParameters(); 
       JobExecution execution = jobLauncher.run(job, param);    
     } catch (Exception e) { 
      LOGGER.error("Can't start job", e); 
      throw new RuntimeException(e); 
     } 
    } 

    public Job getJob() { 
     return job; 
    } 

    public void setJob(Job job) { 
     this.job = job; 
    } 

    public JobLauncher getJobLauncher() { 
     return jobLauncher; 
    } 

    public void setJobLauncher(JobLauncher jobLauncher) { 
     this.jobLauncher = jobLauncher; 
    } 

} 

有沒有辦法不使用RunScheduler類,只是使用XML配置處理呢?

回答

0

您可以使用@EnableScheduling和cronSequenceGenerator的功能進行調度和cron設置,而不依賴於util類。