• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

spring-boot-task: 基于spring-boot 2.x +quartz 的CRUD任务管理系统

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称:

spring-boot-task

开源软件地址:

https://gitee.com/52itstyle/spring-boot-task

开源软件介绍:

spring-boot-task

基于spring-boot 2.x + quartz 的CRUD任务管理系统,适用于中小项目。

基于spring-boot 1.x + quartz 的CRUD任务管理系统:https://gitee.com/52itstyle/spring-boot-quartz

开发环境

JDK1.8、Maven、Eclipse

技术栈

SpringBoot 2.1.6、thymeleaf 3.0.9、quartz 2.3.0、iview、vue、layer、AdminLTE、bootstrap

启动说明

  • 项目使用的数据库为MySql,选择resources/sql中的tables_mysql_innodb.sql文件初始化数据库信息。
  • 在resources/application.properties 以及quartz.properties文件中替换为自己的数据源。
  • 运行Application main方法启动项目,项目启动会自动创建一个测试任务 见:com.itstyle.quartz.config.TaskRunner.java。
  • 项目访问地址:http://localhost:8080/quartz

版本区别(spring-boot 1.x and 2.x)

这里只是针对这两个项目异同做比较,当然spring-boot 2.x版本升级还有不少需要注意的地方。

项目名称配置:

# spring boot 1.xserver.context-path=/quartz# spring boot 2.xserver.servlet.context-path=/quartz

thymeleaf配置:

#spring boot 1.xspring.thymeleaf.mode=LEGACYHTML5#spring boot 2.xspring.thymeleaf.mode=HTML

Hibernate配置:

# 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.PhysicalNamingStrategyStandardImpl

quartz配置:

# 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 * 创建者 小柒2012 * 创建时间	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以被废弃  * 建议实现WebMvcConfigurer接口) * 创建者 小柒2012 * 创建时间  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 );    } }

项目截图

输入图片说明

输入图片说明

输入图片说明

输入图片说明

输入图片说明

输入图片说明

表达式生成器

集群测试

打开quartz集群配置:

# 打开集群配置spring.quartz.properties.org.quartz.jobStore.isClustered = true# 设置集群检查间隔20sspring.quartz.properties.org.quartz.jobStore.clusterCheckinInterval = 2000  

本地跑两个项目,分别设置不同的端口8081和8082,启动成功以后,会发现只有一个任务在跑,然后杀掉在跑的任务,你会发现另一个项目会检测到集群中的一个任务挂了,然后接管任务。

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执行任务,你的任务类需要实现的接口;
  • JobDetail – 定义Job的实例;
  • Trigger – 触发Job的执行;
  • JobBuilder – 定义和创建JobDetail实例的接口;
  • TriggerBuilder – 定义和创建Trigger实例的接口;

作者: 小柒2012

欢迎关注: https://blog.52itstyle.vip


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap