### Spring Boot 2.x整合Quartz
* [官方文檔](https://docs.spring.io/spring-boot/docs/2.0.4.RELEASE/reference/htmlsingle/#boot-features-quartz)
* 導入依賴
~~~
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-quartz</artifactId>
</dependency>
~~~
* 由于定時任務的信息默認保存在內存,當應用重啟后,定時任務信息將會丟失。因此可以使用數據庫存儲定時任務信息,當系統重啟后仍保留定時任務信息,繼續執行之前設置的定時任務。Spring中配置如下:
~~~
spring:
quartz:
# 任務信息存儲至數據庫
job-store-type: jdbc
~~~
* 初始化quartz數據庫表,xboot.sql中已包含,其他數據庫可以到[官網下載](http://www.quartz-scheduler.org/downloads/),Spring Booot 2.x已集成最新v2.3版本,下載解壓后路徑在`quartz-2.2.3-distribution\quartz-2.2.3\docs\dbTables`
* 其他相關配置
~~~
spring:
quartz:
#相關屬性配置
properties:
org:
quartz:
scheduler:
instanceName: clusteredScheduler
instanceId: AUTO
jobStore:
class: org.quartz.impl.jdbcjobstore.JobStoreTX
driverDelegateClass: org.quartz.impl.jdbcjobstore.StdJDBCDelegate
tablePrefix: QRTZ_
isClustered: true
clusterCheckinInterval: 10000
useProperties: false
threadPool:
class: org.quartz.simpl.SimpleThreadPool
threadCount: 10
threadPriority: 5
threadsInheritContextClassLoaderOfInitializingThread: true
~~~