这个有点小问题 尚未解决  后期优化

基于 JobDetailFactoryBean实现

依赖包

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-quartz</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

配置类

package quarttest.demo;

import org.quartz.JobDataMap;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.quartz.CronTriggerFactoryBean;
import org.springframework.scheduling.quartz.JobDetailFactoryBean; @Configuration
public class QuartzConfig { /**
* 在 Quartz 配置类中,主要配置两个东西:1. JobDetail 2. Trigger
* JobDetail 有两种不同的配置方式:
* * 1. MethodInvokingJobDetailFactoryBean 此处是基于方法1 的 即 MethodInvokingJobDetailFactoryBean
* * 2. JobDetailFactoryBean
* @return
*/ @Bean
JobDetailFactoryBean jobDetailFactoryBean() {
JobDetailFactoryBean bean = new JobDetailFactoryBean();
bean.setJobClass(MyJob2.class);
JobDataMap map = new JobDataMap();
map.put("helloService", helloService());
bean.setJobDataMap(map);
return bean;
} @Bean
CronTriggerFactoryBean cronTrigger() {
CronTriggerFactoryBean bean = new CronTriggerFactoryBean();
bean.setCronExpression("0/10 * * * * ?");
bean.setJobDetail(jobDetailFactoryBean().getObject());
return bean;
} @Bean
HelloService helloService() {
return new HelloService();
} }

任务类

package quarttest.demo;

import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.scheduling.quartz.QuartzJobBean;
import org.springframework.stereotype.Component; @Component
public class MyJob2 extends QuartzJobBean {
HelloService helloService; public HelloService getHelloService() {
return helloService;
} public void setHelloService(HelloService helloService) {
this.helloService = helloService;
} @Override
protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
helloService.sayHello();
}
}

具体实现类

package quarttest.demo;

import java.util.Date;

public class HelloService {
public void sayHello() {
System.out.println("hello service >>>"+new Date());
}
}

spring -boot定时任务 quartz 基于 JobDetailFactoryBean实现的更多相关文章

  1. spring -boot定时任务 quartz 基于 MethodInvokingJobDetailFactoryBean 实现

    spring 定时任务 quartz 基于  MethodInvokingJobDetailFactoryBean 实现 依赖包 如下 <dependencies> <depende ...

  2. Spring Boot 定时任务 Quartz 使用教程

    Quartz是一个完全由java编写的开源作业调度框架,他使用非常简单.本章主要讲解 Quartz在Spring Boot 中的使用. 快速集成 Quartz 介绍 Quartz 几个主要技术点 Qu ...

  3. Spring Boot整合Quartz实现定时任务表配置

    最近有个小项目要做,spring mvc下的task设置一直不太灵活,因此在Spring Boot上想做到灵活的管理定时任务.需求就是,当项目启动的时候,如果有定时任务则加载进来,生成schedule ...

  4. spring boot 整合 quartz 集群环境 实现 动态定时任务配置【原】

    最近做了一个spring boot 整合 quartz  实现 动态定时任务配置,在集群环境下运行的 任务.能够对定时任务,动态的进行增删改查,界面效果图如下: 1. 在项目中引入jar 2. 将需要 ...

  5. spring boot整合quartz实现多个定时任务

        版权声明:本文为博主原创文章,转载请注明出处. https://blog.csdn.net/liuchuanhong1/article/details/78543574 最近收到了很多封邮件, ...

  6. Spring Boot定时任务应用实践

    在Spring Boot中实现定时任务功能,可以通过Spring自带的定时任务调度,也可以通过集成经典开源组件Quartz实现任务调度. 一.Spring定时器 1.cron表达式方式 使用自带的定时 ...

  7. spring boot+mybatis+quartz项目的搭建完整版

    1. 利用spring boot提供的工具(http://start.spring.io/)自动生成一个标准的spring boot项目架构 2. 因为这里我们是搭建spring boot+mybat ...

  8. spring boot 整合quartz ,job不能注入的问题

    在使用spring boot 整合quartz的时候,新建定时任务类,实现job接口,在使用@AutoWire或者@Resource时,运行时出现nullpointException的问题.显然是相关 ...

  9. Spring Boot简化了基于Spring的应用开发

    Spring Boot简化了基于Spring的应用开发,通过少量的代码就能创建一个独立的.产品级别的Spring应用. Spring Boot为Spring平台及第三方库提供开箱即用的设置,这样你就可 ...

随机推荐

  1. Python之面向对象之单例模式的四种方式

    一.内容 保证一个类只有一个实例,并提供一个访问它的全局访问点 二.角色 单利 三.使用场景 当类只有一个实例而且客户可以从一个众所周知的访问点访问它时 比如:数据库链接.Socket创建链接 四.优 ...

  2. javascript之定时器的使用

    一:什么是定时器 (一)无限循环定时器 <script> window.onload = function(){ function test(){ alert("test&quo ...

  3. 关于 ant Checkbox.Group 数组checked 设置失效问题

    最近在频繁使用ant UI框架.在使用到checkbox的时候,需要从后台获取数组显示,然后发现数组设置了checked:true,并不能使多选框处于选中状态,阅读 Checkbox Group 的属 ...

  4. 【shell】文本按行逆序

    1.最简单的方法是使用tac [root ~]$ seq |tac 2.使用tr和awk. tr把换行符替换成自定义的分隔符,awk分解替换后的字符串,并逆序输出 [root ~]$ seq | tr ...

  5. 【leetcode】Basic Calculator III

    题目如下: Implement a basic calculator to evaluate a simple expression string. The expression string may ...

  6. “_MSC_VER”的不匹配项

    近些年来vs更新步伐加快,深刻的感受到了技术成长学习的重要性. 另一方面,版本的更换,也带来了许多的问题.今天用2019打开以前2010的工程时就碰到了一个: 检测到“_MSC_VER”的不匹配项: ...

  7. 使用vscode打断点

    1.vscode打开的文件必须只包含你要调适的项目,不能同时在一个vscode打开多个项目窗口 2.点击vscode的这个小蜘蛛 3.选择添加配置 4.此时自动生成了一个文件,launch.json: ...

  8. linux下为已经编译好的php环境添加mysql扩展(php安装完成后如何添加mysql扩展)

    问题背景 平常我们都是先安装mysql,然后才能去安装php.假如先安装php,后安装mysql,由于php需要连接mysql,因而在php引擎中需要配置使用mysql.so扩展.这时需要手动编译生成 ...

  9. 2019hdu多校 Keen On Everything But Triangle

    Problem Description N sticks are arranged in a row, and their lengths are a1,a2,...,aN. There are Q ...

  10. 进程and线程and协程效率对比

    1.进程与进程池的效率对比 多进程:p.start()过程中,只是向操作系统发送一个信号,至于什么时候执行,都是操作系统的事情,操作系统接收到信号时,帮该进程申请一块内存空间+拷贝父进程的地址空间 # ...