zbb20170227_spring_quartz
zbb20170227_spring_quartz
一、Spring3+Quartz2整合
1.quartz2所需jar包
http://download.csdn.net/detail/bobchao0730/9479097
2.spring-task.xml
- <?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>
-
<!-- 配置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>
- package com.ky.task;
- public class MyTask {
- public void run() {
- System.out.println("每天0点执行!");
- }