springboot 集成quartz

1.導入maven依賴:

 <!--quartz相關依賴-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-quartz</artifactId>
        </dependency>

        <!--定時任務需要依賴context模塊-->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context-support</artifactId>
        </dependency>

2.yml配置quartz:

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
    #數據庫方式
    job-store-type: jdbc
instanceName:調度器流程實例名稱
instanceId:調度器流程實例ID
jobStore.class:數據保存方式爲持久化
jobStore.driverDelegateClass:StdJDBCDelegate說明支持集羣
jobStore.tablePrefix:quartz內部表的後綴
jobStore.isClustered:是否集羣

3.jobStore.class配置後,說明我們會使用數據庫進行持久化,然後如果沒有在quartz下面配置job-store-type的話,他會默認創建一個db2數據庫.如果下面配置job-store-type的話就是配置了我們使用的數據庫類型,不配置數據庫的話,他就默認使用當前項目的數據庫.

4.我的數據庫用的是mysql的,解壓quartz的jar,在目錄org\quartz\impl\jdbcjobstore下面,有各種類型數據庫的sql腳本文件,建議大家這樣做,因爲quartz每個版本數據庫結構可能不一樣,這個地方,我就不提供資源了.執行腳本文件,生成表結構.

5.現在我們的集成就完成了.

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章