问题描述
- 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(""看我执行中。。。。""); }}
3web.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 ms2015-3-14 10:21:12 org.apache.catalina.core.StandardService startInternal信息: Starting service Catalina2015-3-14 10:21:12 org.apache.catalina.core.StandardEngine startInternal信息: Starting Servlet Engine: Apache Tomcat/7.0.542015-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:TomcatwebappsHeli]2015-3-14 10:21:19 org.apache.catalina.core.ApplicationContext log信息: Initializing log4j from [D:TomcatwebappsHeliWEB-INFlog4j.properties]2015-3-14 10:21:19 org.apache.catalina.core.ApplicationContext log信息: Initializing Spring root WebApplicationContextservlet初始化。。。。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
以上是全部内容,请问各位大神问题出在哪里了?急死了
解决方案
...
这里的class改用org.springframework.scheduling.quartz.CronTriggerFactoryBean试试
解决方案二:
你好第二步里的
这里的class改用org.springframework.scheduling.quartz.CronTriggerFactoryBean试试
解决方案三:
在第三部的bean里加上 lazy-init=""false"" 这个参数
解决方案四:
这个问题解决了吗,我试了上面的方法,还是不行呢
时间: 2024-11-01 07:04:23