spring+quartz配置的一些变化

1.org.quartz.jobStore.class配置无效

被覆盖配置为org.springframework.scheduling.quartz.LocalDataSourceJobStore

2.调度器名称(SCHED_NAME)由quartzScheduler变为schedulerFactoryBean


我们先来看一下org.quartz.jobStore.class配置无效的情况

使用过quartz的都知道quartz可以使用一个配置文件quartz.properties去设置一些属性例:

org.quartz.jobStore.isClustered: true

org.quartz.jobStore.clusterCheckinInterval: 50000

org.quartz.jobStore.class: org.quartz.impl.jdbcjobstore.JobStoreTX

这样quartz集群环境下使用的存储应该是独立环境的JobStoreTX,方法内会有commit,rollback

但使用了Spring+Quartz之后,发现启动日志里并没有使用JobStoreTX, 而是使用了LocalDataSourceJobStore;具体日志如下:

INFO [2018-10-17 09:06:44,853][main] org.quartz.core.QuartzScheduler[initialize-294] - Scheduler meta-data: Quartz Scheduler (v2.3.0) 'schedulerFactoryBean' with instanceId 'DESKTOP-7U74VP91539738404656'

  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 15 threads.

  Using job-store 'org.springframework.scheduling.quartz.LocalDataSourceJobStore' - which supports persistence. and is clustered.

经过DEBUG启动应用发现

SchedulerFactoryBean实现了接口InitializingBean,因此在实例化完成后会执行afterPropertiesSet方法进行初始化,代码如下

@Override

public void afterPropertiesSet()throws Exception {

if (this.dataSource ==null &&this.nonTransactionalDataSource !=null) {

this.dataSource =this.nonTransactionalDataSource;

  }

if (this.applicationContext !=null &&this.resourceLoader ==null) {

this.resourceLoader =this.applicationContext;

  }

// Create SchedulerFactory instance...

  SchedulerFactory schedulerFactory = BeanUtils.instantiateClass(this.schedulerFactoryClass);

  initSchedulerFactory(schedulerFactory);

initSchedulerFactory

if (this.dataSource !=null) {

mergedProps.put(StdSchedulerFactory.PROP_JOB_STORE_CLASS, LocalDataSourceJobStore.class.getName());

}

// Make sure to set the scheduler name as configured in the Spring configuration.

if (this.schedulerName !=null) {

mergedProps.put(StdSchedulerFactory.PROP_SCHED_INSTANCE_NAME, this.schedulerName);

}

.......

你可能感兴趣的:(spring+quartz配置的一些变化)