Spring集成quart有两种方式,一种是实现Job接口,一种是继承QuartzJobBean

刚开始报错:持久化时未序列化异常

    <bean id="simpleJobDetail"
class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject">
<ref bean="aaa" />
</property>
<property name="targetMethod">
<value>doSth</value>
</property>
</bean>

java.io.NotSerializableException: Unable to serialize JobDataMap for insertion into database because the value of property 'methodInvoker' is not serializable: org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean

原因请看org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean

NOTE: JobDetails created via this FactoryBean are not serializable and thus not suitable for persistent job stores. You need to implement your own Quartz Job as a thin wrapper for each case where you want a persistent job to delegate to a specific service method.

Compatible with Quartz 1.5+ as well as Quartz 2.0-2.2, as of Spring 3.2.

废话不多说直接上主要代码

application.xml

  <bean id="simpleJobDetail" class="org.springframework.scheduling.quartz.JobDetailFactoryBean">
<property name="jobClass" value="com.cntaiping.tpp.tppeservice.job.PrintCurrentTimeJobs" />
<property name="name" value="executeInternal" />
<property name="durability" value="true"></property>
</bean>
<bean id="jobTrigger" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
<property name="jobDetail" >
<ref bean="simpleJobDetail"></ref>
</property>
<property name="cronExpression" >
<value>0 */1 * * * ?</value>
</property>
</bean>
<!-- 启动触发器的配置开始 -->
<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="configLocation" value="classpath:quartz.properties"/>
<property name="dataSource" ref="dataSource"/>
<property name="transactionManager" ref="transactionManager"/>
<property name="schedulerName" value="baseScheduler"/>
<!-- 每台集群机器部署应用的时候会更新触发器-->
<property name="overwriteExistingJobs" value="false"/>
<property name="applicationContextSchedulerContextKey" value="appli"/>
<property name="jobFactory">
<bean class="com.cntaiping.tpp.tppeservice.auth.AutowiringSpringBeanJobFactory"/>
</property>
<property name="triggers">
<list>
<ref bean="jobTrigger"/>
</list>
</property>
<property name="autoStartup" value="true"/> </bean>
PrintCurrentTimeJobs.java(继承QuartzJobBean)
public class PrintCurrentTimeJobs extends QuartzJobBean{
Logger log = Logger.getLogger(JobService.class);
@Autowired
private UserJob userJob; @Override
protected void executeInternal(JobExecutionContext jobExecutionContext) throws JobExecutionException
{
log.info("测试定时任务开始"+new Date());
System.err.println(new Date());
userJob.createTmsUser();
log.info("测试定时任务结束"+new Date());
}
}

QuartJobFactory.java(实现Job接口)

public class QuartJobFactory implements Job {
private Logger log = Logger.getLogger(QuartJobFactory.class);
ScheduleJob scheduleJob ;
@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
scheduleJob = (ScheduleJob) context.getMergedJobDataMap().get("scheduleJob");
StringBuffer sbf = new StringBuffer();
System.err.print(new Date());
} }

quartz.properties

#============================================================================
# Configure Main Scheduler Properties
#============================================================================
org.quartz.scheduler.instanceId: AUTO
org.quartz.scheduler.skipUpdateCheck: true #============================================================================
# Configure ThreadPool
#============================================================================ org.quartz.threadPool.class: org.quartz.simpl.SimpleThreadPool
org.quartz.threadPool.threadCount: 10
org.quartz.threadPool.threadPriority: 5
org.quartz.threadPool.threadsInheritContextClassLoaderOfInitializingThread=true #============================================================================
# Configure JobStore
#============================================================================
org.quartz.jobStore.misfireThreshold: 1000
org.quartz.jobStore.class: org.quartz.impl.jdbcjobstore.JobStoreCMT
org.quartz.jobStore.driverDelegateClass: org.quartz.impl.jdbcjobstore.oracle.weblogic.WebLogicOracleDelegate
org.quartz.jobStore.useProperties: false
org.quartz.jobStore.tablePrefix: QRTZ_ org.quartz.jobStore.isClustered=true
org.quartz.jobStore.clusterCheckinInterval=60000
#============================================================================
# Configure Plugins
#============================================================================
org.quartz.plugin.shutdownHook.class: org.quartz.plugins.management.ShutdownHookPlugin
org.quartz.plugin.shutdownHook.cleanShutdown: true org.quartz.plugin.triggHistory.class: org.quartz.plugins.history.LoggingJobHistoryPlugin

  

Spring整合quart初识的更多相关文章

  1. 初识quartz 并分析 项目中spring整合quartz的配置【原创+转载】

    初识quartz 并分析 项目中spring整合quartz的配置[原创+转载]2018年01月29日 12:08:07 守望dfdfdf 阅读数:114 标签: quartz 更多个人分类: 工具 ...

  2. 使用Spring整合Quartz轻松完成定时任务

    一.背景 上次我们介绍了如何使用Spring Task进行完成定时任务的编写,这次我们使用Spring整合Quartz的方式来再一次实现定时任务的开发,以下奉上开发步骤及注意事项等. 二.开发环境及必 ...

  3. 【Java EE 学习 53】【Spring学习第五天】【Spring整合Hibernate】【Spring整合Hibernate、Struts2】【问题:整合hibernate之后事务不能回滚】

    一.Spring整合Hibernate 1.如果一个DAO 类继承了HibernateDaoSupport,只需要在spring配置文件中注入SessionFactory就可以了:如果一个DAO类没有 ...

  4. spring整合hibernate的详细步骤

    Spring整合hibernate需要整合些什么? 由IOC容器来生成hibernate的sessionFactory. 让hibernate使用spring的声明式事务 整合步骤: 加入hibern ...

  5. Spring整合Ehcache管理缓存

    前言 Ehcache 是一个成熟的缓存框架,你可以直接使用它来管理你的缓存. Spring 提供了对缓存功能的抽象:即允许绑定不同的缓存解决方案(如Ehcache),但本身不直接提供缓存功能的实现.它 ...

  6. spring整合hibernate

    spring整合hibernate包括三部分:hibernate的配置.hibernate核心对象交给spring管理.事务由AOP控制 好处: 由java代码进行配置,摆脱硬编码,连接数据库等信息更 ...

  7. MyBatis学习(四)MyBatis和Spring整合

    MyBatis和Spring整合 思路 1.让spring管理SqlSessionFactory 2.让spring管理mapper对象和dao. 使用spring和mybatis整合开发mapper ...

  8. Mybatis与Spring整合,使用了maven管理项目,作为初学者觉得不错,转载下来

    转载自:http://www.cnblogs.com/xdp-gacl/p/4271627.html 一.搭建开发环境 1.1.使用Maven创建Web项目 执行如下命令: mvn archetype ...

  9. Spring整合HBase

    Spring整合HBase Spring HBase SHDP § 系统环境 § 配置HBase运行环境 § 配置Hadoop § 配置HBase § 启动Hadoop和HBase § 创建Maven ...

随机推荐

  1. YouTube数据:谁获得了最多订阅者?

    原文来源: https://www.kaggle.com/roshan77/youtube-data-who-got-the-most-subscribers 介绍: Python笔记 使用来自Soc ...

  2. 《python for data analysis》第七章,数据规整化

    <利用Python进行数据分析>第七章的代码. # -*- coding:utf-8 -*-# <python for data analysis>第七章, 数据规整化 imp ...

  3. NodeJS 学习笔记

    1. NodeJs的事件模型被称为非阻塞式IO或者事件驱动IO 2. Node.js 几乎每一个 API 都是支持回调函数的. 3. Node.js 基本上所有的事件机制都是用设计模式中观察者模式实现 ...

  4. opendistro 试用

    以前转载过一篇别人的关于opendistro的文章,还好使用docker-compose 运行,很方便,所以自己也跑下 环境准备 docker-compose 文件 version: '3' serv ...

  5. C 逻辑运算, 移位运算 , 取整 , 取模(取余)

    一. 按位运算 (快速操作数据的某个位) ^   按位异或 ~  按位取反 &  按位与 |  按位或 二. 逻辑运算 &&  逻辑与   有一个值为 0 ,值为 0 ||  ...

  6. windows 端口转发

    1.添加端口转发 netsh interface portproxy add v4tov4 listenport=5000 listenaddress=10.30.3.148 connectport= ...

  7. Faster-RCNN理解

    一.Faster-RCNN基本结构 该网络结构大致分为三个部分:卷积层得到高位图像特征feature maps.Region Proposal Network得到候选边框.classifier识别出物 ...

  8. maven:Fatal error compiling: 无效的目标 发行版: 1.8 -> [Help 1]

    https://blog.csdn.net/kkgbn/article/details/72777750

  9. [ZZ] 用matlab绘制箭头

    用matlab绘制箭头 http://npfeng900.blog.163.com/blog/static/14456108201221922944998/ 用matlab绘制箭头1 用matlab绘 ...

  10. RK3399 友善NanoPC-T4开发板使用sysfs方法控制status LED状态灯-【申嵌视频-RK3399篇】

    实验1:sysfs 操作方法控制NanoPC-T4开发板上LED灯 (status LED状态灯:GPIO0_B5/LED1_OUT)root@NanoPC-T4: cd /sys/class/led ...