spring+quartz做的定时任务,tomcat启动没问题,就是定时任务不执行,是什么原因?-问答-阿里云开发者社区-阿里云

开发者社区> 问答> 正文
阿里云
为了无法计算的价值
打开APP
阿里云APP内打开

spring+quartz做的定时任务,tomcat启动没问题,就是定时任务不执行,是什么原因?

1.applicationContext_quartz.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:aop="http://www.springframework.org/schema/aop"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="
    http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/aop 
    http://www.springframework.org/schema/aop/spring-aop.xsd
    http://www.springframework.org/schema/tx 
    http://www.springframework.org/schema/tx/spring-tx.xsd">
    <!-- Spring定时任务 -->
    <!-- 定时任务 -->
    <bean id="quartzAction" class="com.test.action.QuartzTaskAction"/>
    <!-- 第一步:指定执行的类的方法名 -->
        <bean id="xhhf_jd" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
           <property name="targetObject"><ref bean="quartzAction"/></property>
           <property name="targetMethod"><value>xhhfDates</value></property>
        </bean>
    <!-- 第二步:指定触发的类型 -->
        <bean id="xhhf_ct" class="org.springframework.scheduling.quartz.CronTriggerBean">
           <property name="jobDetail"><ref bean="xhhf_jd" /></property>
           <property name="cronExpression" value="0/2 * * * * ?" /> 
        </bean>
    <!-- 第三步:开启定时任务 -->
    <bean id="startQuertz" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
        <property name="triggers">
           <list>
              <ref bean="xhhf_ct"/>
           </list>
       </property>
    </bean>
</beans>

2.QuartzTaskAction.action内容

package com.test.action;

public class QuartzTaskAction{
    public void xhhfDates(){
        System.out.println("看我执行中。。。。");
    }
}

3.web.xml配置内容

 <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
            /WEB-INF/config/applicationContext_*.xml
        </param-value>
  </context-param>

4.tomcat启动日志

2015-3-14 10:21:11 org.apache.catalina.core.AprLifecycleListener init
信息: Loaded APR based Apache Tomcat Native library 1.1.30 using APR version 1.4.8.
2015-3-14 10:21:11 org.apache.catalina.core.AprLifecycleListener init
信息: APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true].
2015-3-14 10:21:12 org.apache.catalina.core.AprLifecycleListener initializeSSL
信息: OpenSSL successfully initialized (OpenSSL 1.0.1g 7 Apr 2014)
2015-3-14 10:21:12 org.apache.coyote.AbstractProtocol init
信息: Initializing ProtocolHandler ["http-apr-80"]
2015-3-14 10:21:12 org.apache.coyote.AbstractProtocol init
信息: Initializing ProtocolHandler ["ajp-apr-8009"]
2015-3-14 10:21:12 org.apache.catalina.startup.Catalina load
信息: Initialization processed in 1196 ms
2015-3-14 10:21:12 org.apache.catalina.core.StandardService startInternal
信息: Starting service Catalina
2015-3-14 10:21:12 org.apache.catalina.core.StandardEngine startInternal
信息: Starting Servlet Engine: Apache Tomcat/7.0.54
2015-3-14 10:21:19 org.apache.tomcat.websocket.server.WsSci onStartup
信息: JSR 356 WebSocket (Java WebSocket 1.0) support is not available when running on Java 6. To suppress this message, run Tomcat on Java 7, remove the WebSocket JARs from $CATALINA_HOME/lib or add the WebSocket JARs to the tomcat.util.scan.DefaultJarScanner.jarsToSkip property in $CATALINA_BASE/conf/catalina.properties. Note that the deprecated Tomcat 7 WebSocket API will be available. 
2015-3-14 10:21:19 org.apache.catalina.core.ApplicationContext log
信息: Set web app root system property: 'Heli' = [D:\Tomcat\webapps\Heli\]
2015-3-14 10:21:19 org.apache.catalina.core.ApplicationContext log
信息: Initializing log4j from [D:\Tomcat\webapps\Heli\WEB-INF\log4j.properties]
2015-3-14 10:21:19 org.apache.catalina.core.ApplicationContext log
信息: Initializing Spring root WebApplicationContext
servlet初始化。。。。
2015-3-14 10:21:29 com.sun.faces.config.ConfigureListener contextInitialized
信息: 初始化上下文 '' 的 Mojarra 2.0.3 (FCS b03)
2015-3-14 10:21:30 com.sun.faces.spi.InjectionProviderFactory createInstance
信息: JSF1048:有 PostConstruct/PreDestroy 注释。标有这些注释的 ManagedBeans 方法将表示注释已处理。
2015-3-14 10:21:33 org.apache.coyote.AbstractProtocol start
信息: Starting ProtocolHandler ["http-apr-80"]
2015-3-14 10:21:33 org.apache.coyote.AbstractProtocol start
信息: Starting ProtocolHandler ["ajp-apr-8009"]
2015-3-14 10:21:33 org.apache.catalina.startup.Catalina start
信息: Server startup in 21100 ms 

展开
收起
小旋风柴进 2016-03-03 13:37:51 8835 0
1 条回答
写回答
取消 提交回答
  • 小旋风柴进

    你好第二步里的
    这里的class改用
    org.springframework.scheduling.quartz.CronTriggerFactoryBean试试
    第三部的bean里加上 lazy-init="false" 这个参数

    2019-07-17 18:51:18
    赞同 展开评论 打赏
问答排行榜
最热
最新
相关电子书
更多
Spring Boot2.0实战Redis分布式缓存
立即下载
Java Spring Boot开发实战系列课程【第16讲】:Spring Boot 2.0 实战Apache Kafka百万级高并发消息中间件与原理解析
立即下载
Java Spring Boot开发实战系列课程(第17讲):Spring Boot 2.0实战Docker容器Linux
立即下载