quartz配置_基于spring-boot 2.x +quartz 的CRUD任务管理系统
生活随笔
收集整理的這篇文章主要介紹了
quartz配置_基于spring-boot 2.x +quartz 的CRUD任务管理系统
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
基于spring-boot 2.x + quartz 的CRUD任務(wù)管理系統(tǒng),適用于中小項目。
開發(fā)環(huán)境
JDK1.8、Maven、Eclipse
技術(shù)棧
SpringBoot 2.0.1、thymeleaf 3.0.9、quartz 2.3.0、iview、vue、layer、AdminLTE、bootstrap
啟動說明
- 項目使用的數(shù)據(jù)庫為MySql,選擇resources/sql中的tables_mysql_innodb.sql文件初始化數(shù)據(jù)庫信息。
- 在resources/application.properties文件中替換為自己的數(shù)據(jù)源。
- 運行Application main方法啟動項目,項目啟動會自動創(chuàng)建一個測試任務(wù) 見:com.itstyle.quartz.config.TaskRunner.java。
- 項目訪問地址:http://localhost:8080/quartz
項目名稱配置:
# spring boot 1.xserver.context-path=/quartz# spring boot 2.xserver.servlet.context-path=/quartzthymeleaf配置:
#spring boot 1.xspring.thymeleaf.mode=LEGACYHTML5#spring boot 2.xspring.thymeleaf.mode=HTMLHibernate配置:
# spring boot 2.x JPA 依賴 Hibernate 5# Hibernate 4 naming strategy fully qualified name. Not supported with Hibernate 5.spring.jpa.hibernate.naming.strategy = org.hibernate.cfg.ImprovedNamingStrategy# stripped before adding them to the entity manager)spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect# Hibernate 5spring.jpa.hibernate.naming.implicit-strategy=org.hibernate.boot.model.naming.ImplicitNamingStrategyLegacyJpaImplspring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImplquartz配置:
# spring boot 2.x 已集成Quartz,無需自己配置spring.quartz.job-store-type=jdbcspring.quartz.properties.org.quartz.scheduler.instanceName=clusteredSchedulerspring.quartz.properties.org.quartz.scheduler.instanceId=AUTOspring.quartz.properties.org.quartz.jobStore.class=org.quartz.impl.jdbcjobstore.JobStoreTXspring.quartz.properties.org.quartz.jobStore.driverDelegateClass=org.quartz.impl.jdbcjobstore.StdJDBCDelegatespring.quartz.properties.org.quartz.jobStore.tablePrefix=QRTZ_spring.quartz.properties.org.quartz.jobStore.isClustered=truespring.quartz.properties.org.quartz.jobStore.clusterCheckinInterval=10000spring.quartz.properties.org.quartz.jobStore.useProperties=falsespring.quartz.properties.org.quartz.threadPool.class=org.quartz.simpl.SimpleThreadPoolspring.quartz.properties.org.quartz.threadPool.threadCount=10spring.quartz.properties.org.quartz.threadPool.threadPriority=5spring.quartz.properties.org.quartz.threadPool.threadsInheritContextClassLoaderOfInitializingThread=true默認首頁配置:
/** * 配置首頁 spring boot 1.x * 創(chuàng)建者 小柒2012 * 創(chuàng)建時間2017年9月7日 */@Configurationpublic class MyAdapter extends WebMvcConfigurerAdapter{ @Override public void addViewControllers( ViewControllerRegistry registry ) { registry.addViewController( "/" ).setViewName( "forward:/login.shtml" ); registry.setOrder( Ordered.HIGHEST_PRECEDENCE ); super.addViewControllers( registry ); } }/** * 配置首頁(在SpringBoot2.0及Spring 5.0 WebMvcConfigurerAdapter以被廢棄 * 建議實現(xiàn)WebMvcConfigurer接口) * 創(chuàng)建者 小柒2012 * 創(chuàng)建時間 2018年4月10日 */@Configurationpublic class MyAdapter implements WebMvcConfigurer{ @Override public void addViewControllers( ViewControllerRegistry registry ) { registry.addViewController( "/" ).setViewName( "forward:/login.shtml" ); registry.setOrder( Ordered.HIGHEST_PRECEDENCE ); } }待解決問題:
/** * Set a strategy for handling the query results. This can be used to change * "shape" of the query result. * * @param transformer The transformer to apply * * @return this (for method chaining) * * @deprecated (since 5.2) * @todo develop a new approach to result transformers */@DeprecatedQuery setResultTransformer(ResultTransformer transformer);hibernate 5.2 廢棄了 setResultTransformer,說是要開發(fā)一種新的獲取集合方法,顯然目前還沒實現(xiàn),處于TODO狀態(tài)。
項目截圖
集群測試
打開quartz集群配置:
# 打開集群配置spring.quartz.properties.org.quartz.jobStore.isClustered:true# 設(shè)置集群檢查間隔20sspring.quartz.properties.org.quartz.jobStore.clusterCheckinInterval = 2000本地跑兩個項目,分別設(shè)置不同的端口8081和8082,啟動成功以后,會發(fā)現(xiàn)只有一個任務(wù)在跑,然后殺掉在跑的任務(wù),你會發(fā)現(xiàn)另一個項目會檢測到集群中的一個任務(wù)掛了,然后接管任務(wù)。
2018-04-12 09:00:01.792 INFO 7488 --- [_ClusterManager] o.s.s.quartz.LocalDataSourceJobStore : ClusterManager: detected 1 failed or restarted instances.2018-04-12 09:00:01.793 INFO 7488 --- [_ClusterManager] o.s.s.quartz.LocalDataSourceJobStore : ClusterManager: Scanning for instance "itstyle-PC1523496348539"'s failed in-progress jobs.2018-04-12 09:00:01.839 INFO 7488 --- [_ClusterManager] o.s.s.quartz.LocalDataSourceJobStore : ClusterManager: ......Freed 1 acquired trigger(s).大吉大利、今晚吃雞-01大吉大利、今晚吃雞-01擴展
Quartz API核心接口有:
- Scheduler – 與scheduler交互的主要API;
- Job – 你通過scheduler執(zhí)行任務(wù),你的任務(wù)類需要實現(xiàn)的接口;
- JobDetail – 定義Job的實例;
- Trigger – 觸發(fā)Job的執(zhí)行;
- JobBuilder – 定義和創(chuàng)建JobDetail實例的接口;
- TriggerBuilder – 定義和創(chuàng)建Trigger實例的接口;
項目地址
- 基于spring-boot 2.x + quartz 的CRUD任務(wù)管理系統(tǒng):https://gitee.com/52itstyle/spring-boot-task
- 基于spring-boot 1.x + quartz 的CRUD任務(wù)管理系統(tǒng):https://gitee.com/52itstyle/spring-boot-quartz
總結(jié)
以上是生活随笔為你收集整理的quartz配置_基于spring-boot 2.x +quartz 的CRUD任务管理系统的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python回复qq消息_自动给qq好友
- 下一篇: href可以请求后台么_href怎么进行