2016-05-24 79 views
1
@Component 
    public class JobScheduler { 
    private static final Log logger = LogFactory.getLog(JobScheduler.class); 

    @Autowired 
    private JobLauncher jobLauncher; 

    @Autowired 
    private Job job; 

    @Scheduled(cron = "0 0/1 * * * ?") 
    public void run() { 
     try { 
      String dateParam = new Date().toString(); 
      JobParameters param = new JobParametersBuilder().addString("date", dateParam).toJobParameters(); 
      jobLauncher.run(job, param); 
     } catch (Exception e) { 
      logger.error(e.getStackTrace()); 
     } 
    } 

    } 

批處理作業的XML是:春季批次管理不觸發計劃任務

<?xml version="1.0" encoding="UTF-8"?> 
    <beans xmlns="http://www.springframework.org/schema/beans" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:task="http://www.springframework.org/schema/task" 
xmlns:context="http://www.springframework.org/schema/context" 
xsi:schemaLocation=" 
    http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch.xsd 
    http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.1.xsd 
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd 
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> 


<context:annotation-config /> 
<context:component-scan base-package="org.springframework.batch.admin.sample" /> 

<job id="infinite1" xmlns="http://www.springframework.org/schema/batch"> 
    <step id="step1"> 
     <tasklet start-limit="100"> 
      <chunk commit-interval="1" reader="itemReader" writer="itemWriter" /> 
     </tasklet> 
    </step> 
</job> 

<bean id="itemWriter" class="org.springframework.batch.admin.sample.ExampleItemWriter"/> 
<bean id="itemReader" class="org.springframework.batch.admin.sample.ExampleItemReader" scope="step"/> 

<task:scheduled-tasks> 
    <task:scheduled ref="jobScheduler" method="run" cron="0 0/1 * * * ?"/> 
</task:scheduled-tasks> 

<bean id="jobScheduler" class="org.springframework.batch.admin.sample.JobScheduler" /> 

我使用它自帶的STS 3.6 cron表達式應該捆綁在一起的VMWare的vFabric TC服務器每隔一分鐘就觸發一次infinite1工作。但事實並非如此。任何指針將不勝感激。

+0

你有沒有得到這個解決?如果是這樣,你的解決方案是什麼? – Rick

+1

@Rick - 不,我們不能讓這個工作,所以我們把它放在積壓,並轉移到其他項目。 – ashwin

回答

0

試着把@EnableScheduling放進你的班級

+0

使用該註釋會導致此錯誤:「在Bean目標類'SimpleJobService'上找到@Scheduled方法'removeInactiveExecutions',但在動態代理的任何接口中找不到」。即使使用註釋@EnableAspectJAutoProxy(proxyTargetClass = true),仍然會得到相同的錯誤。 使用SBA 2.0.0.BUILD-SNAPSHOT和Spring Batch Core 3.0.7.RELEASE – Rick