<?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:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.1.xsd">
<!-- The class to be called by the timer-->
<bean id="reportQuartzJob" class="com.cooker.RunningDayReportJob" />
<!-- Define the calling object and the method of calling the object -->
<bean id="jobTask"
class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<!-- Called class -->
<property name="targetObject" ref="reportQuartzJob" />
<!-- call a method in the class -->
<property name="targetMethod" value="work"/>
</bean>
<!-- define trigger time-->
<bean id="trunckTime" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
<property name="jobDetail" ref="jobTask" />
<property name="cronExpression">
<!-- Statistics of application operation at 1:00 a.m. every day-->
<value>0 0 1 * * ?</value>
<!-- The task is scheduled to be executed once every 2 minutes. Test-->
<!-- <value>0 */1 * * * ?</value> -->
</property>
</bean>
<!-- If the general management class sets lazy-init='false', the scheduler will be executed when the container starts -->
<bean id="startQuertz" lazy-init="true" autowire="no" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref bean="trunckTime" />
</list>
</property>
</bean>
</beans>
在 web.xml 加入 配置文件
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:config/spring/spring-application.xml,
classpath:config/spring/spring-support.xml,
classpath:config/spring/spring-mybatis.xml,
classpath:config/spring/spring-cache.xml,
classpath:config/spring/spring-quartz.xml
</param-value>
</context-param>