Spring整合quart初识
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初识的更多相关文章
- 初识quartz 并分析 项目中spring整合quartz的配置【原创+转载】
初识quartz 并分析 项目中spring整合quartz的配置[原创+转载]2018年01月29日 12:08:07 守望dfdfdf 阅读数:114 标签: quartz 更多个人分类: 工具 ...
- 使用Spring整合Quartz轻松完成定时任务
一.背景 上次我们介绍了如何使用Spring Task进行完成定时任务的编写,这次我们使用Spring整合Quartz的方式来再一次实现定时任务的开发,以下奉上开发步骤及注意事项等. 二.开发环境及必 ...
- 【Java EE 学习 53】【Spring学习第五天】【Spring整合Hibernate】【Spring整合Hibernate、Struts2】【问题:整合hibernate之后事务不能回滚】
一.Spring整合Hibernate 1.如果一个DAO 类继承了HibernateDaoSupport,只需要在spring配置文件中注入SessionFactory就可以了:如果一个DAO类没有 ...
- spring整合hibernate的详细步骤
Spring整合hibernate需要整合些什么? 由IOC容器来生成hibernate的sessionFactory. 让hibernate使用spring的声明式事务 整合步骤: 加入hibern ...
- Spring整合Ehcache管理缓存
前言 Ehcache 是一个成熟的缓存框架,你可以直接使用它来管理你的缓存. Spring 提供了对缓存功能的抽象:即允许绑定不同的缓存解决方案(如Ehcache),但本身不直接提供缓存功能的实现.它 ...
- spring整合hibernate
spring整合hibernate包括三部分:hibernate的配置.hibernate核心对象交给spring管理.事务由AOP控制 好处: 由java代码进行配置,摆脱硬编码,连接数据库等信息更 ...
- MyBatis学习(四)MyBatis和Spring整合
MyBatis和Spring整合 思路 1.让spring管理SqlSessionFactory 2.让spring管理mapper对象和dao. 使用spring和mybatis整合开发mapper ...
- Mybatis与Spring整合,使用了maven管理项目,作为初学者觉得不错,转载下来
转载自:http://www.cnblogs.com/xdp-gacl/p/4271627.html 一.搭建开发环境 1.1.使用Maven创建Web项目 执行如下命令: mvn archetype ...
- Spring整合HBase
Spring整合HBase Spring HBase SHDP § 系统环境 § 配置HBase运行环境 § 配置Hadoop § 配置HBase § 启动Hadoop和HBase § 创建Maven ...
随机推荐
- ML_Clustering
西瓜书学习...ing K均值 k-means 给定样本集$ D = {X_1,X_2,...X_n} \(,k-means针对聚类所得簇划分\)C = {C_1,C_2,...,C_k}$最小化平方 ...
- sqlmap的安装
来自:http://www.51testing.com/html/89/n-3711589.html 一.下载 首先,需下载SqlMap以及适用于Windows系统的Python.下载地址如下: 1. ...
- source-insight 常用操作
[Ctrl + ] 跳转到函数.宏.变量 等定义处. [Alt > ] 跳转到最近光标停留位置. [Alt < ] 跳转到上次近光标停留位置. [Ctrl Shift [ ] 块位置开 ...
- 自己DIY出来一个JSON结构化展示器
说来也巧,这个玩意,一直都想亲手写一个,因为一直用着各种网上提供的工具,觉得这个还是有些用途,毕竟,后面的实现思路和原理不是太复杂,就是对json的遍历,然后给予不同节点类型以不同的展现风格. 我这次 ...
- linux中脚本在任意目录执行
完成了一个脚本,find.sh 如果希望可以再linux系统中任何位置都可以执行该脚本,可以执行下面操作 1. chmod 775 find.sh 给该脚本增加可执行权限 2. export PATH ...
- catkin_make编译错误
在工作空间下编译ros的代码包,报错如下, CMake Error at LeGO-LOAM/LeGO-LOAM/CMakeLists.txt: (find_package): By not prov ...
- LeetCode——688. Knight Probability in Chessboard
一.题目链接:https://leetcode.com/problems/knight-probability-in-chessboard/ 二.题目大意: 给定一个N*N的棋盘和一个初始坐标值(r, ...
- 利用微信支付的订单查询接口可以在APP 中提高支付的可靠性
最近公司有一个应用,用户可以在微信公众号上面下单,也可以在APP 中下单. 当用户在公共号上面下单时,微信支付成功可以返回微信支付单号,但是在APP 中用户微信支付时,个别时候会出现用户已经付款成功, ...
- IDEA汉化
1.- 汉化包 提取码: 4mbq 2.打开IDEA,执行下列操作:在主界面选择File → Settings → Appearance&Behavior → Appearance → 勾选O ...
- 【Python爬虫】01:网络爬虫--规则
Python网络爬虫与信息提取 目标:掌握定向网络数据爬取和网页解析的基本能力. the website is the API 课程分为以下部分: 1.requsets库(自动爬取HTML页面.自动网 ...