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. vue day5 分页控件

    <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...

  2. P2257 莫比乌斯+整除分块

    #include<bits/stdc++.h> #define ll long long using namespace std; ; int vis[maxn]; int mu[maxn ...

  3. 学习笔记CB003:分块、标记、关系抽取、文法特征结构

    分块,根据句子的词和词性,按照规则组织合分块,分块代表实体.常见实体,组织.人员.地点.日期.时间.名词短语分块(NP-chunking),通过词性标记.规则识别,通过机器学习方法识别.介词短语(PP ...

  4. Python爬虫初学者学习笔记(带注释)

    一,安装编程工具并进入编程界面 首先去https://www.continuum.io/downloads/网站下载Anaconda工具并安装;打开cmd,输入jupyter notebook并回车( ...

  5. Beginning Math and Physics For Game Programmers (Wendy Stahler 著)

    Chapter 1. Points and Lines (已看) Chapter 2. Geometry Snippets (已看) Chapter 3. Trigonometry Snippets  ...

  6. java8_api_misc

    属性文件处理    概念    加载并读取文件内容    修改文件内容    获取系统属性        该文件是一个文本文件,以properties作为其后缀,内容格式为    key1=value ...

  7. VUE踩坑之路

    一.常见报错 1.vue-cli-service 不是内部或外部命令,也不是可运行程序 解决方案: 用以下命令安装Vue CLI就好 npm install -g @vue/cli # OR yarn ...

  8. Shell脚本出现$'\r': command not found

    Centos7下执行shell脚本报错如下 [root@ip---- ~]# sh install_zabbix_agent.sh install_zabbix_agent.: $'\r': comm ...

  9. tcpdump+wireshark抓包分析

    上一篇文章中,我们介绍了tcpdump如何抓包. tcpdump是命令行下便捷的抓包和分析工具,但使用方式不够友好, wireshark是带图形化界面的抓包和分析工具,操作简便,但需要主机有显示器. ...

  10. abstract class VS interface

    关于抽象类 abstract class: 1. 抽象方法必须在抽象类中 2. 抽象类和抽象方法要用abstract 关键字修饰 3. 不可以用new 来实例化一个abstract类,因为调用抽象方法 ...