Я пытаюсь запланировать задание spring batch
с quartz scheduler
.
Я выполнил этот учебник , чтобы добиться этого.
когда я бегу в модульном тесте он не работал должным образом, и сообщение об ошибке не выводилось. (ожидаемое поведение: запускать весеннее пакетное задание каждые 19 секунд)
Это трассировка стека после запуска проекта:
INFO 08/04 11:54:04 [o.h.t.h.SchemaExport][main] HHH000230: Schema export complete
DEBUG 08/04 11:54:05 [n.s.e.u.UpdateChecker][net.sf.ehcache.CacheManager@4cff7287] Checking for update...
INFO 08/04 11:54:05 [o.s.b.c.l.s.SimpleJobLauncher][main] No TaskExecutor has been set, defaulting to synchronous executor.
INFO 08/04 11:54:05 [o.q.i.StdSchedulerFactory][main] Using default implementation for ThreadExecutor
INFO 08/04 11:54:05 [o.q.c.SchedulerSignalerImpl][main] Initialized Scheduler Signaller of type: class org.quartz.core.SchedulerSignalerImpl
INFO 08/04 11:54:05 [o.q.c.QuartzScheduler][main] Quartz Scheduler v.2.2.1 created.
INFO 08/04 11:54:05 [o.q.s.RAMJobStore][main] RAMJobStore initialized.
INFO 08/04 11:54:05 [o.q.c.QuartzScheduler][main] Scheduler meta-data: Quartz Scheduler (v2.2.1)
'org.springframework.scheduling.quartz.SchedulerFactoryBean#0' with instanceId 'NON_CLUSTERED'
Scheduler class: 'org.quartz.core.QuartzScheduler' - running locally.
NOT STARTED.
Currently in standby mode.
Number of jobs executed: 0
Using thread pool 'org.quartz.simpl.SimpleThreadPool' - with 10 threads.
Using job-store 'org.quartz.simpl.RAMJobStore' - which does not support persistence. and is not clustered.
INFO 08/04 11:54:05 [o.q.i.StdSchedulerFactory][main] Quartz scheduler 'org.springframework.scheduling.quartz.SchedulerFactoryBean#0' initialized from an externally provided properties instance.
INFO 08/04 11:54:05 [o.q.i.StdSchedulerFactory][main] Quartz scheduler version: 2.2.1
INFO 08/04 11:54:05 [o.q.c.QuartzScheduler][main] JobFactory set to: org.springframework.scheduling.quartz.AdaptableJobFactory@4602f47
INFO 08/04 11:54:05 [o.s.c.s.DefaultLifecycleProcessor$LifecycleGroup][main] Starting beans in phase 2147483647
INFO 08/04 11:54:05 [o.s.s.q.SchedulerFactoryBean][main] Starting Quartz Scheduler now
INFO 08/04 11:54:05 [o.q.c.QuartzScheduler][main] Scheduler org.springframework.scheduling.quartz.SchedulerFactoryBean#0_$_NON_CLUSTERED started.
И это мои конфигурации:
Класс модульного тестирования :
public class TestJobLauncherDetails {
private static final Logger LOG = LoggerFactory.getLogger(TestJobLauncherDetails .class);
@Test
public void test() throws Exception {
ApplicationContext context = new ClassPathXmlApplicationContext("beanRefContext.xml");
}
}
JobLauncherDetails. java
public class JobLauncherDetails extends QuartzJobBean {
static final String JOB_NAME = "jobName";
private JobLocator jobLocator;
private JobLauncher jobLauncher;
public void setJobLocator(JobLocator jobLocator) {
this.jobLocator = jobLocator;
}
public void setJobLauncher(JobLauncher jobLauncher) {
this.jobLauncher = jobLauncher;
}
@SuppressWarnings("unchecked")
protected void executeInternal(JobExecutionContext context) {
Map<String, Object> jobDataMap = context.getMergedJobDataMap();
String jobName = (String) jobDataMap.get(JOB_NAME);
JobParameters jobParameters = getJobParametersFromJobMap(jobDataMap);
try {
jobLauncher.run(jobLocator.getJob(jobName), jobParameters);
} catch (JobExecutionException e) {
e.printStackTrace();
}
}
//get params from jobDataAsMap property, job-quartz.xml
private JobParameters getJobParametersFromJobMap(Map<String, Object> jobDataMap) {
JobParametersBuilder builder = new JobParametersBuilder();
for (Entry<String, Object> entry : jobDataMap.entrySet()) {
String key = entry.getKey();
Object value = entry.getValue();
if (value instanceof String && !key.equals(JOB_NAME)) {
builder.addString(key, (String) value);
} else if (value instanceof Float || value instanceof Double) {
builder.addDouble(key, ((Number) value).doubleValue());
} else if (value instanceof Integer || value instanceof Long) {
builder.addLong(key, ((Number) value).longValue());
} else if (value instanceof Date) {
builder.addDate(key, (Date) value);
} else {
// JobDataMap contains values which are not job parameters
// (ignoring)
}
}
//need unique job parameter to rerun the same job
builder.addDate("run date", new Date());
return builder.toJobParameters();
}
xml конфигурация:
<bean
class="org.springframework.batch.core.configuration.support.JobRegistryBeanPostProcessor">
<property name="jobRegistry" ref="jobRegistry" />
</bean>
<bean id="jobRegistry"
class="org.springframework.batch.core.configuration.support.MapJobRegistry" />
<bean id="CarteDao"
class="mypkg.CarteDaoImpl" />
<bean id="ClientDao"
class="mypkg.dao.ClientDaoImpl" />
<bean id="JobDao"
class="mypkg.dao.JobDaoImpl" />
<bean id="csvToDatabaseReader"
class="mypkg.reader.CsvToDatabaseReader"
scope="step">
<property name="ndCampagneDao" ref="ndCampagneDao" />
<property name="CarteDao" ref="CarteDao" />
<property name="ClientDao" ref="ClientDao" />
<property name="JobDao"
ref="JobDao" />
</bean>
<!-- csv file writer -->
<bean id="csvToDatabaseWriter"
class="mypkg.writer.CsvToDatabaseWriter"
scope="step">
<property name="ndCampagneDao" ref="ndCampagneDao" />
</bean>
<!-- partitioner job -->
<job id="partitionJob"
xmlns="http://www.springframework.org/schema/batch">
<step id="masterStep">
<partition step="slave" partitioner="raPartitioner">
<handler grid-size="10" task-executor="taskExecutor" />
</partition>
</step>
</job>
<!-- Jobs to run -->
<step id="slave"
xmlns="http://www.springframework.org/schema/batch">
<tasklet>
<chunk reader="catReader"
writer="caWriter" processor="caProcessor"
commit-interval="1" />
</tasklet>
</step>
<bean id="raPartitioner"
class="mypkg.processing.RaPartitioner">
<property name="CaDao" ref="CaDao" />
</bean>
<bean id="taskExecutor"
class="org.springframework.core.task.SimpleAsyncTaskExecutor" />
<bean id="CaDao"
class="mypkg.dao.CaDaoImpl" />
<bean id="caReader"
class="mypkg.reader.CaReader"
scope="step">
<property name="CaDao" ref="CaDao" />
</bean>
<bean id="caProcessor"
class="mypkg.processor.CaProcessor"
scope="step">
<property name="threadName"
value="#{stepExecutionContext[name]}" />
</bean>
<!-- csv file writer -->
<bean id="caWriter"
class="mypkg.writer.CaWriter"
scope="step">
<property name="CaDao" ref="CaDao" />
</bean>
<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<bean id="cronTrigger" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
<property name="jobDetail" ref="jobDetail" />
<property name="cronExpression" value="*/19 * * * * ?" />
</bean>
</property>
</bean>
<bean id="jobRepository"
class="org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean">
<property name="transactionManager" ref="transactionManager" />
</bean>
<bean id="transactionManager"
class="org.springframework.batch.support.transaction.ResourcelessTransactionManager" />
<bean id="jobLauncher"
class="org.springframework.batch.core.launch.support.SimpleJobLauncher">
<property name="jobRepository" ref="jobRepository" />
</bean>
<bean id="jobDetail" class="org.springframework.scheduling.quartz.JobDetailFactoryBean">
<property name="jobClass" value="mypkg.scheduler.JobLauncherDetails" />
<property name="group" value="quartz-batch" />
<property name="jobDataAsMap">
<map>
<entry key="jobName" value="partitionJob" />
<entry key="jobLocator" value-ref="jobRegistry" />
<entry key="jobLauncher" value-ref="jobLauncher" />
</map>
</property>
</bean>
что-то отсутствует или неправильное в моем коде?
Кстати: когда я запускаю пакетное задание Spring вручную, оно работает отлично
Заранее спасибо .