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 ...
 
随机推荐
- 解题报告 『机器翻译(vector)』
			
原题地址 本想练习一下模拟,不过用vector貌似可以轻松水过?(虽然还是模拟) 但突然发现貌似我并不会判断单词是否在内存中出现过? 最后还是靠度娘解决了. 代码如下: #include <bi ...
 - [小明打联盟][斜率/单调队列 优化dp][背包]
			
链接:https://ac.nowcoder.com/acm/problem/14553来源:牛客网 题目描述 小明很喜欢打游戏,现在已知一个新英雄即将推出,他同样拥有四个技能,其中三个小技能的释放时 ...
 - mySql 数据库中间件 atlas的使用
			
MySQL 中间件Atlas 实现读写分离 原创 MySQL 作者:神谕丶 时间:2016-08-05 17:07:51 2410 0 〇 Atlas架构介绍 <span "=&q ...
 - ubuntu 安装 pycharm
			
添加源: $ sudo add-apt-repository ppa:mystic-mirage/pycharm 安装收费的专业版: $ sudo apt update $ sudo apt in ...
 - 3. Port scanners (端口扫描器 4个)
			
3. Port scanners (端口扫描器 4个) 愤怒的IP扫描器是一个小的开源Java应用程序,它执行主机发现(“ping扫描”)和端口扫描. 旧的2.x版本只有Windows,但是,新的3. ...
 - time模块的用法和转化关系
			
Time模块的用法和互相转化关系 UTC(Coordinated Universal Time,世界协调时)亦即格林威治天文时间,世界标准时间.在中国为UTC+8.DST(Daylight Savin ...
 - 18.7 修改IP地址
			
ifconfig #查看ip sudo ifconfig eth3 10.3.10.232 #修改ip
 - Java ConcurrentHashMap存入引用对象时也是线程安全的
			
本人小白,看到资料说ConcurrentHashMap是线程安全的,get过程不需要加锁,put是线程安全的,推荐高并发时使用.但是本人不清楚是否该map中存入的引用类型对象,对象属性变化也是否线程安 ...
 - Oracle数据csv导入
			
打开工具,在tool下面有个Text Importer 先选择Data from textfile选项卡 然后选择 Open data file ,打开要导入的文件 1\ 2\ 再先选择Data to ...
 - 查看CentOS版本
			
1. 查看核心版本 $ uname -or $ uname -a 2. rpm $ rpm --query centos-release [On CentOS] $ rpm --query redha ...