quartz框架沒問題。web
流程:spring
sping-quartz配置spring-mvc
<?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:mvc="http://www.springframework.org/schema/mvc" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:task="http://www.springframework.org/schema/task" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.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.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.0.xsd "> <context:annotation-config/> <task:annotation-driven/> <!-- 業務對象 --> <bean id="testJobTask" class="com.sunyard.quartz.TestQuartzTask" /> <!-- 自動掃描包 --> <context:component-scan base-package="com.sunyard.quartz.*" /> <!-- 定時任務start --> <!-- 調度業務 --> <bean id="jobDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"> <property name="targetObject" ref="testJobTask" /> <property name="targetMethod" value="execute" /> </bean> <!-- 增長調用的觸發器,觸發時間 並注入到調度工廠--> <bean id="cronTrigger" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean"> <property name="jobDetail" ref="jobDetail" /> <property name="cronExpression" value="0/10 * * * * ? *" /> </bean> <!-- 設置調度工廠 注入觸發器--> <bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean"> <property name="triggers"> <list> <ref bean="cronTrigger" /> </list> </property> </bean> <!-- 定時任務end --> </beans>
以後在web.xml中mybatis
<listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <context-param> <param-name>contextConfigLocation</param-name> <param-value> classpath:spring-mybatis.xml, classpath:spring-quartz.xml </param-value> </context-param>
測試mvc
/** * 定時任務--打印測試定時任務是否成功 * @author wang * */ public class TestQuartzTask{ public void execute() { System.out.println("定時任務已啓動!"); } }
以後發現啓動以後輸出兩行,即任務啓動兩次。app
最終解決:框架
<Host appBase="" autoDeploy="true" name="localhost" unpackWARs="true">
將appBase置空便可測試