quartz---springmvc的配置文件正合

XML

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
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-4.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.0.xsd">
<!-- first -->
<!-- <bean name="firstSimpleJobDetail"
class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject" ref="myBean"></property>
<property name="targetMethod" value="helloBean"></property>
</bean> -->
<!-- secodent -->
<bean name="simpleJobDetail"
class="org.springframework.scheduling.quartz.JobDetailFactoryBean">
<property name="jobClass" value="com.taotao.web.bean.FirstScheduledJob"></property>
<property name="jobDataMap">
<map>
<entry key="anotherBean" value-ref="anotherBean"></entry>
</map>
</property>
<property name="Durability" value="true" />
</bean>
<!-- 距离当前时间2分钟后执行,之后每隔两秒钟执行一次 -->
<!-- <bean id="SimpleTrigger"
class="org.springframework.scheduling.quartz.SimpleTriggerFactoryBean">
<property name="jobDetail" ref="simpleJobDetail"></property>
<property name="startDelay" value="1000"></property>
<property name="repeatInterval" value="2000"></property>
</bean> -->
<!-- cronTrigger -->
<bean id="firstSimlpeTrigger"
class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
<property name="jobDetail" ref="simpleJobDetail"></property>
<!-- 每30秒每分每月每周执行一次 -->
<property name="cronExpression" value="0/5 * * ? * *"/>
</bean>
<!-- 触发器启动 -->
<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="jobDetails">
<list>
<ref bean="firstSimpleJobDetail"></ref>
<ref bean="simpleJobDetail"></ref>
</list>
</property>
<property name="triggers">
<list>
<ref bean="SimpleTrigger"></ref>
<ref bean="firstSimlpeTrigger"></ref>
</list>
</property>
</bean>
</beans>

myBean

package com.taotao.web.bean;

import java.text.SimpleDateFormat;
import java.util.Date; import org.springframework.stereotype.Component; @Component("myBean")
public class MyBean { public void helloBean(){
Date date=new Date();
SimpleDateFormat sf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
System.out.println("MyBean"+sf.format(date));
}
}

AnotherBean

package com.taotao.web.bean;

import org.springframework.stereotype.Component;

@Component("anotherBean")
public class AnotherBean { public void printlnL() {
System.out.println("HUHU");
}
}

FirstScheduledJob

package com.taotao.web.bean;

import java.text.SimpleDateFormat;
import java.util.Date; import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.scheduling.quartz.QuartzJobBean; public class FirstScheduledJob extends QuartzJobBean { private AnotherBean anotherBean; public void setAnotherBean(AnotherBean anotherBean) {
this.anotherBean = anotherBean;
} @Override
protected void executeInternal(JobExecutionContext arg0) throws JobExecutionException {
Date date = new Date();
SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
System.out.println("hello FirstScheduledJob Executes!" + sf.format(date));
this.anotherBean.printlnL();
} }

      以上代码使用了2中方法实现了定时任务器:

    1)两种绑定方法

        1.org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean

        2.org.springframework.scheduling.quartz.JobDetailFactoryBean

      都利用了工厂模式。

    2)两种触发方式:

        1.org.springframework.scheduling.quartz.SimpleTriggerFactoryBean

        2.org.springframework.scheduling.quartz.CronTriggerFactoryBean

    3)一个触发器:

         org.springframework.scheduling.quartz.SchedulerFactoryBean

        

quartz---springmvc的配置文件正合的更多相关文章

  1. SpringMVC深度探险(四) —— SpringMVC核心配置文件详解

    在上一篇文章中,我们从DispatcherServlet谈起,最终为读者详细分析了SpringMVC的初始化主线的全部过程.整个初始化主线的研究,其实始终围绕着DispatcherServlet.We ...

  2. 关于springmvc的配置文件

    开发常用的springmvc.xml配置文件,spring 3.0 spring-servlet.xml配置. <?xml version="1.0" encoding=&q ...

  3. 3.SpringMVC修改配置文件路径和给界面传递数据

    1.修改配置文件路径  达到  配置多文件的目的 web.xml文件中基础配置有springMVC配置的servlet路径 <servlet-name>SpringMVC</serv ...

  4. quartz.net 的配置文件资料

    java版本的文档比较全 http://www.quartz-scheduler.org/documentation/quartz-2.x/configuration/ConfigPlugins.ht ...

  5. Quartz+SpringMVC实现web定时管理任务

    代码地址如下:http://www.demodashi.com/demo/13978.html 使用背景 相信大家在工作过程中,肯定会遇到很多任务定时执行,修改定时任务的时间,执行一次定时任务等等.下 ...

  6. ssm框架 spring的主配置文件 spring-mvc主配置文件 web.xml配置文件(基础的配置文件)

    1.spring主配置文件 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns=" ...

  7. (转)SpringMVC学习(三)——SpringMVC的配置文件

    http://blog.csdn.net/yerenyuan_pku/article/details/72231527 读者阅读过SpringMVC学习(一)——SpringMVC介绍与入门这篇文章后 ...

  8. Spring+SpringMVC整合----配置文件

    1.在 web.xml 中加载 spring 的配置文件 bean.xml    底层是 Listener <!-- Spring --> <context-param> &l ...

  9. 加载自定义目录下的springmvc.xml配置文件

    在默认情况下:springmvc框架的配置文件必须叫<servlet-name>-servlet.xml 且必须放在/WEB-INF/目录下,我们可以在web.xml文件中,为Dispat ...

随机推荐

  1. JavaScript甜点(1)

    甜点1:什么是脚本语言? 脚本语言是由传统编程语言简化而来的,它与传统的编程语言既有很多相似之处,又有很多的不同之处.脚本语言的最显著的特点是:首先它不需要编译成二进制,以文本的形式存在:其次就是脚本 ...

  2. 添加用户到 sudo

    sudo 简介: 在 Linux 中系统管理员可以通过 sudo 实用程序让用户或组能够作为另一个用户运行命令.换句话说,可以分派命令特权,而不需要另一个用户的密码.root 用户通过在 /etc/s ...

  3. UNIX系统的显示时间何时会到尽头

    本文转载自:http://www.cnblogs.com/dfcao/p/expertCprogramming_intr0.html 本文分为三个小块: 一.UNIX系统中时间的存储形式: 二. ti ...

  4. E: could not get lock /var/lib/dpkg/lock-frontend - open (11: Resource temporary unavailable) E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), is an other process using it

    1. 问题详细提示如下: E: Could not get lock /var/lib/dpkg/lock-frontend - open (11: Resource temporarly unava ...

  5. ubuntu14.04禁止触摸板和恢复触摸板

    1.使用xinput list查看与触摸板相关的id,以下是本机的输出,没搞清楚为什么是Mouse!!! jello@jello:~$ xinput list⎡ Virtual core pointe ...

  6. redis linux版本自定义安装目录、注册服务、自启动设置、一台计算机安装多个redis

    自定义安装目录并安装 1.mkdir /usr/local/redis 2.下载redis到 /usr/local/src/,解压,进入解压后的目录 3.安装到指定目录 make PREFIX=/us ...

  7. P4-Related Tools Installation

    P4-Related Tools Installation 安装P4相关工具的步骤和说明. 本说明只适用于 Ubuntu 14.04 系统. 推荐安装的其他工具 mininet:SDN网络仿真工具 v ...

  8. Ubuntu Eclipse ns3编译中 遇到的OSError 系列问题

    问题1:Permission denied 解决方法:修改文件权限,利用 chmod 命令 修改在 /home/wasdns/workspace/MyNS3_Mac/ns-3.25 (eclipse工 ...

  9. UVa 116 单向TSP(多段图最短路)

    https://cn.vjudge.net/problem/UVA-116 题意:给出m行n列的整数矩阵,从第一列任何一个位置出发每次往右,右上或右下走一格,最终到达最后一列,要求经过的整数之和最小. ...

  10. UVa 12325 宝箱

    https://vjudge.net/problem/UVA-12325 题意:有一个体积为N的箱子和两种数量无限的宝物.宝物1的体积为S1,价值为V1‘宝物2的体积为S2,价值为V2.计算出最多能装 ...