@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工作。但事實並非如此。任何指針將不勝感激。
你有沒有得到這個解決?如果是這樣,你的解決方案是什麼? – Rick
@Rick - 不,我們不能讓這個工作,所以我們把它放在積壓,並轉移到其他項目。 – ashwin