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. USB开发库STSW-STM32121文件分析

    hw_config.c: 该文件中包含系统配置的函数. usb_desc.c:各种描述符 usb-endp.c:就两个函数分别处理端点1的IN和端点2的OUT. usb_istr.c: 该文件中只有一 ...

  2. 根据wsdl,axis2工具生成客户端代码

    根据wsdl,axis2工具生成客户端代码 步骤: 1,下载axis2版本http://axis.apache.org/axis2/java/core/download.html 2,下载完成后解压, ...

  3. golang debug调试

    1. debug by gdb: office doc download the runtime-gdb file. $ wget -q -O - https://golang.org/src/run ...

  4. oracle、Mysql数据库客户端DbVisualizer安装

    原文链接:https://jingyan.baidu.com/article/454316ab675302f7a7c03a9e.html

  5. Duilib 实现右下角弹出像QQ新闻窗口,3秒后自动关闭(一)

    转载:https://blog.twofei.com/667/ 自绘或子类化控件时,有时需要处理鼠标进入(MouseEnter)/鼠标离开(MouseLeave)/鼠标停留(MouseHover)消息 ...

  6. 通过例子来理解python闭包。

    闭包:就是内部函数对enclosing作用域的变量进行引用.(可先参考python函数作用域LEGB) 通过一个例子体会 def func_150(val): passline = 90 if val ...

  7. 史丰收速算|2014年蓝桥杯B组题解析第四题-fishers

    史丰收速算 史丰收速算法的革命性贡献是:从高位算起,预测进位.不需要九九表,彻底颠覆了传统手算! 速算的核心基础是:1位数乘以多位数的乘法. 其中,乘以7是最复杂的,就以它为例. 因为,1/7 是个循 ...

  8. Spring的面向切面

    Spring的面向切面 在应用开发中,有很多类似日志.安全和事务管理的功能.这些功能都有一个共同点,那就是很多个对象都需要这些功能.复用这些通用的功能的最简单的方法就是继承或者委托.但是当应用规模达到 ...

  9. 51nod 1106 质数检测

    #include <bits/stdc++.h> using namespace std; int n; ; bool s[maxn]; void is_prime() { memset( ...

  10. bootstrap栅格系统进行偏移格式

    本文为博主原创,转载请注明出处: offset偏移都是向右偏移,且只能向右偏移,例: col-md-offset-2,向右偏移两列. col-md-pull-偏移数值         //向左偏移 c ...