首页 > 代码库 > zbb20170227_spring_quartz
zbb20170227_spring_quartz
一、Spring3+Quartz2整合
1.quartz2所需jar包
http://download.csdn.net/detail/bobchao0730/9479097
2.spring-task.xml
[html] view plain copy
- <?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:tx="http://www.springframework.org/schema/tx"
- xmlns:aop="http://www.springframework.org/schema/aop"
- xmlns:context="http://www.springframework.org/schema/context"
- xmlns:mvc="http://www.springframework.org/schema/mvc"
- xsi:schemaLocation="
- http://www.springframework.org/schema/beans
- http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
- http://www.springframework.org/schema/aop
- http://www.springframework.org/schema/aop/spring-aop-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/tx
- http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
- http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
- ">
- <!-- 使用MethodInvokingJobDetailFactoryBean,任务类可以不实现Job接口,通过targetMethod指定调用方法 -->
- <bean id="taskJob" class="com.ky.task.MyTask"></bean>
- <bean id="jobDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
- <property name="group" value="job_work"/>
- <property name="name" value="job_work_name"/>
- <!-- false表示等上一个任务执行完成后再开启新的任务 -->
- <property name="concurrent" value="false"/>
- <property name="targetObject">
- <ref bean="taskJob"/>
- </property>
- <property name="targetMethod">
- <value>run</value>
- </property>
- </bean>
- <!-- 调度触发器 -->
- <bean id="myTrigger" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
- <property name="group" value="work_default"/>
- <property name="name" value="work_default_name"/>
- <property name="jobDetail">
- <ref bean="jobDetail"/>
- </property>
- <!-- 每天0点执行 -->
- <property name="cronExpression">
- <value>0/5 * * * * ?</value>
- </property>
- </bean>
- <!-- 调度工厂 -->
- <bean id="scheduler" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
- <property name="triggers">
- <list>
- <ref bean="myTrigger"/>
- </list>
- </property>
- </bean>
- </beans>
[html] view plain copy
-
<!-- 配置spring mvc -->
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:com/zbb/config/spring-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
[java] view plain copy
- package com.ky.task;
- public class MyTask {
- public void run() {
- System.out.println("每天0点执行!");
- }
zbb20170227_spring_quartz
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。