spring中配置quartz定时器
2016-07-21 18:37
666 查看
spring中配置quartz定时器
jar包说明
spring3.0+quartz1.0版本,这里如果使用quartz2.0的话,spring的jar包要3.2版本以上下载地址:http://download.csdn.net/detail/dzy21/9582333
实体类的方法
定时器就来调用这个方法package com.cloud.impl; public class GetDataImpl { public void getData(){ System.out.println("测试定时器的数据拉取..."); } } |
spring配置文件
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context" xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"> <!-- 配置一个定时器 --> <bean id="getDataImpl" class="com.cloud.impl.GetDataImpl"></bean> <!-- 定时器:获取数据第一步 --> <bean id="getDataQuart" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"> <!-- 配置获取数据的service --> <property name="targetObject" ref="getDataImpl"/> <!-- 配置执行的method --> <property name="targetMethod" value="getData"/> <!-- 设置作业不并发调度 --> <property name="concurrent" value="false" /> </bean> <!-- 定时器:设置定时启动时间 --> <bean id="getDataTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean"> <property name="jobDetail" ref="getDataQuart"/> <!-- 每天凌晨开始,每30分钟拉取一次数据 --> <property name="cronExpression"> <value>0 0-59/1 0-23 * * ?</value> </property> </bean> <!-- 定时器:启动定时器 --> <bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean"> <property name="triggers"> <list> <!-- 这里可以设置多个要启动的定时器 --> <ref bean="getDataTrigger"/> </list> </property> </bean> </beans> |
web.xml配置文件
<?xml version="1.0" encoding="UTF-8"?> <web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"> <display-name></display-name> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> <!-- 配置Spring文件加载 --> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:applicationContext.xml</param-value> </context-param> <!-- 配置监听 --> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> </web-app> |
相关文章推荐
- java中对于页面传入ids的数组进行的批量操作
- Eclipse juno 中安装 JBoss Tools,集成Hibernate
- eclipse 常用快捷键
- Spring相关名词(0)
- javaMail邮件发送
- 学习《spring 3.x企业应用开发实战》之Spring对DAO的支持
- java实现顺序栈
- [Spring]Spring Bean的初始化 ---- getBean方法
- java.lang.IllegalArgumentException
- java爬虫爬取网页内容前,对网页内容的编码格式进行判断的方式
- RxJava 详解
- Java 多线程:Lock接口(接口方法分析,ReentrantLock,ReadWriteLock 3ff8
- 线程池的理解
- Java_IO_File
- Android 4.4Eclipse项目中使用RecyclerView
- java web使用Cookie进行会话管理
- (2)Spring框架
- Java Web中cookie和session详解
- java中的 private Logger log=Logger.getLogger(this.getClass());
- eclipse高亮选中属性以及更改颜色