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
你好第二步里的
这里的class改用org.springframework.scheduling.quartz.CronTriggerFactoryBean
试试
第三部的bean里加上 lazy-init="false" 这个参数
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。