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. TED #10# A rite of passage for late life

    Bob Stein: A rite of passage for late life Collection I grew up white, secular and middle class in 1 ...

  2. Linux下tomcat6.0与jdk安装

    Linux下tomcat6.0与jdk安装 步骤如下: 1. 上传apache-tomcat-6.0.37.tar.gz和jdk-6u13-linux-i586.bin至/usr/local 给这两个 ...

  3. ELK之elasticsearch6.5集群

    前面介绍并初试了es6.5系列的单节点的操作,现在搭建es6.5系列的集群: 环境:三节点:master-172.16.23.128.node1-172.16.23.129.node2-172.16. ...

  4. JavaScript中变量提升------Hoisting

    原谅链接:http://www.cnblogs.com/damonlan/archive/2012/07/01/2553425.html 因为这个问题很是经典,而且容易出错,所以在介绍一次.哈哈.莫怪 ...

  5. git如何列出分支之间的差异commit

    答:使用git log master..diff_master 这样就可以列出在diff_master分支中包含的commit而在master分支中不包含的commit

  6. bootstrap3

    bs是基于html5和css3的, h5和css3是今后的趋势. html5只是说文档的 "标准"是h5, 但是文档的类型仍然是 html. 所以在写文档类型的时候, 就不能要那个 ...

  7. C#中的异步编程模式

    异步编程模型(APM) 基于事件的异步编程模式 基于任务的异步模式 Async Await编程 关于C#,可以看看Learning Hard的博客

  8. Unity3D学习笔记(九):摄像机

    3D数学复习 using System.Collections; using System.Collections.Generic; using UnityEngine; public class w ...

  9. UVa 1347 旅行

    https://vjudge.net/problem/UVA-1347 思路:用d(i,j)表示第一个人走到i,第二个人走到j,还需要走多长的距离.在这里强制定义i>j,并且每次只能走到i+1. ...

  10. c++ 在指定长度的数组或者容器中,统计元素出现的次数(count)

    #include <iostream> // cout #include <algorithm> // count #include <vector> // vec ...