spring 任务调度quartz
简单记录一下spring任务调度quartz的例子
首先添加包
quartz-2.2.3.jar
然后写个简单的TestJob类
package com.job;
import java.util.Date;
public class TestJob {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public void excute(){
System.out.println(name+"===定时任务:"+new Date());
}
}
再加配置文件application-job.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd" > <bean id="testJob" class="com.job.TestJob">
<property name="name" value="testtest"></property> <!-- 给testJob里的name属性赋值 -->
</bean> <bean id="testJobDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject" ref="testJob"></property> <!-- 调用testJob -->
<property name="targetMethod" value="execute" /> <!-- testJob里的execute()方法 -->
<property name="concurrent" value="false" /><!-- 作业不并发调度 -->
</bean> <bean id="testJobCron" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
<property name="jobDetail" ref="testJobDetail" /> <!-- 调用 id="testJobDetail"的 bean -->
<property name="cronExpression" value="0/5 * * * * ?" /> <!-- 每5秒执行一次 -->
</bean> <!-- 总管理类 如果将lazy-init='false'那么容器启动就会执行调度程序 -->
<bean id="schedulerFactoryBean" lazy-init="false" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref bean="testJobCron" /> <!-- 调用 id="testJobCron"的 bean -->
</list>
</property>
</bean>
</beans>
最后应该加web.xml里载一下配置文件
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:application-*.xml</param-value>
</context-param>
估计大概应该也许或者就差不多可以了吧
spring 任务调度quartz的更多相关文章
- Spring任务调度之Quartz
一.Quartz作业类的继承方式来讲,可以分为两类: 作业类需要继承自特定的作业类基类,如Quartz中需要继承自org.springframework.scheduling.quartz.Quart ...
- 分布式任务调度——quartz + spring + 数据库
项目中使用分布式并发部署定时任务,多台跨JVM,按照常理逻辑每个JVM的定时任务会各自运行,这样就会存在问题,多台分布式JVM机器的应用服务同时干活,一个是加重服务负担,另外一个是存在严重的逻 ...
- spring中的任务调度Quartz
Spring 整合 Quartz 任务调度 主要有两种方式. Quartz的官网:http://www.quartz-scheduler.org/ 这两种只是一些配置文件简单配置就OK了,但是根本无法 ...
- Spring Boot Quartz 分布式集群任务调度实现
Spring Boot Quartz 主要内容 Spring Scheduler 框架 Quartz 框架,功能强大,配置灵活 Quartz 集群 mysql 持久化定时任务脚本(tables_mys ...
- spring整合quartz时间任务调度框架
spring整合quartz框架 1.创建maven工程 2.导入jar包(pom.xml) <dependencies> <dependency> <groupId&g ...
- 使用Spring整合Quartz轻松完成定时任务
一.背景 上次我们介绍了如何使用Spring Task进行完成定时任务的编写,这次我们使用Spring整合Quartz的方式来再一次实现定时任务的开发,以下奉上开发步骤及注意事项等. 二.开发环境及必 ...
- spring整合quartz并持久化
spring整合quartz有两种方式: 一.常见是使用配置文件,将定时任务保存到内存中 简单示例: <!-- 短信催还提醒任务调度 --> <bean id="overd ...
- Spring中Quartz调度器的使用
一.Quartz的特点 * 按作业类的继承方式来分,主要有以下两种: 1.作业类继承org.springframework.scheduling.quartz.QuartzJobBean类的方式 2. ...
- Spring整合Quartz实现动态定时器
一.版本说明 spring3.1以下的版本必须使用quartz1.x系列,3.1以上的版本才支持quartz 2.x,不然会出错. 原因:spring对于quartz的支持实现,org.springf ...
随机推荐
- php list的用法
<?php $my_array = array("Dog","Cat","Horse"); list($a, $b, $c) = $m ...
- 17.3.12---xmlrpclib模块
1----XML-RPC是一种使用xml文本的方式利用http协议传输命令和数据的rpc基址,我们用pythom的想mlrpclib模块可以让程序与其他任何语言编写的XML-RPC服务器进行数据传输 ...
- linux设置网络三种方法
http://blog.csdn.net/u010003835/article/details/52233296
- PAT Basic 1075 链表元素分类(25) [链表]
题目 给定⼀个单链表,请编写程序将链表元素进⾏分类排列,使得所有负值元素都排在⾮负值元素的前⾯,⽽[0, K]区间内的元素都排在⼤于K的元素前⾯.但每⼀类内部元素的顺序是不能改变的.例如:给定链表为 ...
- SVN提交时忽略不必提交的文件夹和文件,如node_modules
空白处右键>选中TortoiseSVN>设置(settings)>常规设置(General)>Subversion>编辑(edit)>在弹出的config文件中找g ...
- 关于CSS中的字体尺寸设置 em rem
常用单位 在CSS中可以用很多不同的方式来设定字体的尺寸.一般来说,这些单位被分成两大类:绝对单位(absolute)和相对单位(relative). 绝对单位在大多数情况下是相对于某些实际量度而言的 ...
- 关于mysql数据库连接异常处理
tomcat启动错误日志关键信息: 28-Aug-2019 14:22:55.014 SEVERE [localhost-startStop-1] org.apache.catalina.core.C ...
- [Algo] 253. Longest Substring Without Repeating Characters
Given a string, find the longest substring without any repeating characters and return the length of ...
- 吴裕雄--天生自然 PYTHON3开发学习:条件控制
if condition_1: statement_block_1 elif condition_2: statement_block_2 else: statement_block_3 var1 = ...
- android weight