1.下载quartz-all-1.7.3.jar包

a.在Spring配置和Quartz集成内容时,有两点需要注意

b.在<Beans>中不能够设置default-lazy-init="true",否则定时任务不触发,如果不明确指明default-lazy-init的值,默认是false。

c.在<Beans>中不能够设置default-autowire="byName"的属性,否则后台会报org.springframework.beans.factory.BeanCreationException错误,这样就不能通过Bean名称自动注入,必须      通过明确引用注入

2.java类

package com.newtouch.modules.coco.utils;

import org.apache.log4j.Logger;

public class TaskJob{

public static Logger log = Logger.getLogger(TaskJob.class);
public void runJob() {
// TODO Auto-generated method stub
try {
log.info("处理任务开始>........");
// 业务逻辑代码调用
System.out.println("时间[" + new java.util.Date().toLocaleString()
+ "]----->大家好啊!");
log.info("处理任务结束!");
} catch (Exception e) {
log.error("处理任务出现异常", e);
}
}

}

3.配置文件

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd" >

<bean name="taskJob" class="com.newtouch.modules.coco.utils.TaskJob" />

<!-- 引用任务描述 -->
<bean id="methodInvokingJobDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="concurrent">
<value>false</value>
</property>
<property name="targetObject">
<ref bean="taskJob" />
</property>
<property name="targetMethod">
<value>runJob</value>
</property>
</bean>
<!-- 配置触发器 -->
<bean id="cronTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
<!-- 这里不可以直接在属性jobDetail中引用taskJob,因为他要求的是一个jobDetail类型的对象,所以我们得通过MethodInvokingJobDetailFactoryBean来转一下 -->
<property name="jobDetail">
<ref bean="methodInvokingJobDetail" />
</property>

<property name="cronExpression">
<!-- 每1分钟跑一次 -->
<value>0 0/1 * * * ?</value>
</property>
</bean>

<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<!-- 添加触发器 -->
<property name="triggers">
<list>
<ref bean="cronTrigger" />
</list>
</property>
</bean>

</beans>

spring mvc 定时器的更多相关文章

  1. spring mvc 篇

    [1]spring mvc 实现多文件上传 http://blog.csdn.net/a1314517love/article/details/24183273 http://bbs.csdn.net ...

  2. Spring MVC Web.xml配置

    Web.xml spring&spring mvc 在web.xml中定义contextConfigLocation参数,Spring会使用这个参数去加载所有逗号分隔的xml文件,如果没有这个 ...

  3. 如何用Java类配置Spring MVC(不通过web.xml和XML方式)

    DispatcherServlet是Spring MVC的核心,按照传统方式, 需要把它配置到web.xml中. 我个人比较不喜欢XML配置方式, XML看起来太累, 冗长繁琐. 还好借助于Servl ...

  4. Spring MVC重定向和转发以及异常处理

    SpringMVC核心技术---转发和重定向 当处理器对请求处理完毕后,向其他资源进行跳转时,有两种跳转方式:请求转发与重定向.而根据要跳转的资源类型,又可分为两类:跳转到页面与跳转到其他处理器.对于 ...

  5. Spring MVC入门

    1.什么是SpringMvc Spring MVC属于SpringFrameWork的后续产品,已经融合在Spring Web Flow里面.Spring 框架提供了构建 Web 应用程序的全功能 M ...

  6. Spring7:基于注解的Spring MVC(下篇)

    Model 上一篇文章<Spring6:基于注解的Spring MVC(上篇)>,讲了Spring MVC环境搭建.@RequestMapping以及参数绑定,这是Spring MVC中最 ...

  7. Spring6:基于注解的Spring MVC(上篇)

    什么是Spring MVC Spring MVC框架是一个MVC框架,通过实现Model-View-Controller模式来很好地将数据.业务与展现进行分离.从这样一个角度来说,Spring MVC ...

  8. 高性能的关键:Spring MVC的异步模式

    我承认有些标题党了,不过话说这样其实也没错,关于“异步”处理的文章已经不少,代码例子也能找到很多,但我还是打算发表这篇我写了好长一段时间,却一直没发表的文章,以一个更简单的视角,把异步模式讲清楚. 什 ...

  9. Java Spring mvc 操作 Redis 及 Redis 集群

    本文原创,转载请注明:http://www.cnblogs.com/fengzheng/p/5941953.html 关于 Redis 集群搭建可以参考我的另一篇文章 Redis集群搭建与简单使用 R ...

随机推荐

  1. Activiti开启SQL Log

    log4j.logger.org.activiti.engine.impl.persistence.entity=trace

  2. iOS开发 - OC - 苹果为大家提供的后台:CloudKit 的简单使用

    一.什么是cloudKit 移动开发中,网络请求数据是日常中用到的,我们习惯把一些用户改动的数据存在服务器,以便下次请求使用.或者开发者方通过服务器将编辑的数据发送给用户.但是这一切都建立在我们的AP ...

  3. [手机取证] “神器”IP-BOX的一些问题

    网上最近传的纷纷扬扬的iOS密码破解神器IP-BOX,很多人感兴趣,作为一个该产品的老用户,来破除一下迷信,顺便做个普及~ Q1:这东西好神奇,是不是所有都能破解? A1:支持简单密码的穷举,有条件的 ...

  4. unity中的WWW通讯问题

    网上很多写到WWW的问题. 一.局限性比较大,使用不方便二.WWW类的使用不符合微软的命名规范三.在大量并发使用WWW类会发生"Too Many Threads"的异常 确实有些, ...

  5. 根据word模板(contract_templet.tld)生成并下载word合同及根据wordHTML模板(contract_templetHTML.tld)预览合同内容

    1.action String templete=ConstantsAppParams.CONTRACT_TEMPLET_DOC;//contract_templet.tldString temple ...

  6. android 程序代码执行adb

    Runtime.getRuntime().exec("adb pull /dev/graphics/fb0 C:/fb1"); Runtime. getRuntime().exec ...

  7. Unable to install breakpoint in

    Unable to install breakpoint inXXXX due to missing line number attributes.modify compiler options to ...

  8. JS传递对象数组为参数给后端,后端获取

    前端JS代码: var conditons = []; var test1 = new Object(); test1.name="1"; test1.id="2&quo ...

  9. 在requirejs中使用qunit

    requirejs(['QUnit'], function(qunit) { qunit.test('test name', function(assert) { // 一些测试, assert }) ...

  10. Zepto 使用过程中遇到的问题总结

    简言之,zepto 是移动端的 jQuery,虽然很多地方不完全相同,不过详细的内容就不介绍了,主要把使用 zepto 时遇到过的问题总结一下. zepto 是分成多个模块的,最基础的文件不包含 to ...