quartz---springmvc的配置文件正合
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的配置文件正合的更多相关文章
- SpringMVC深度探险(四) —— SpringMVC核心配置文件详解
在上一篇文章中,我们从DispatcherServlet谈起,最终为读者详细分析了SpringMVC的初始化主线的全部过程.整个初始化主线的研究,其实始终围绕着DispatcherServlet.We ...
- 关于springmvc的配置文件
开发常用的springmvc.xml配置文件,spring 3.0 spring-servlet.xml配置. <?xml version="1.0" encoding=&q ...
- 3.SpringMVC修改配置文件路径和给界面传递数据
1.修改配置文件路径 达到 配置多文件的目的 web.xml文件中基础配置有springMVC配置的servlet路径 <servlet-name>SpringMVC</serv ...
- quartz.net 的配置文件资料
java版本的文档比较全 http://www.quartz-scheduler.org/documentation/quartz-2.x/configuration/ConfigPlugins.ht ...
- Quartz+SpringMVC实现web定时管理任务
代码地址如下:http://www.demodashi.com/demo/13978.html 使用背景 相信大家在工作过程中,肯定会遇到很多任务定时执行,修改定时任务的时间,执行一次定时任务等等.下 ...
- ssm框架 spring的主配置文件 spring-mvc主配置文件 web.xml配置文件(基础的配置文件)
1.spring主配置文件 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns=" ...
- (转)SpringMVC学习(三)——SpringMVC的配置文件
http://blog.csdn.net/yerenyuan_pku/article/details/72231527 读者阅读过SpringMVC学习(一)——SpringMVC介绍与入门这篇文章后 ...
- Spring+SpringMVC整合----配置文件
1.在 web.xml 中加载 spring 的配置文件 bean.xml 底层是 Listener <!-- Spring --> <context-param> &l ...
- 加载自定义目录下的springmvc.xml配置文件
在默认情况下:springmvc框架的配置文件必须叫<servlet-name>-servlet.xml 且必须放在/WEB-INF/目录下,我们可以在web.xml文件中,为Dispat ...
随机推荐
- Java的各种加密算法
Java的各种加密算法 JAVA中为我们提供了丰富的加密技术,可以基本的分为单向加密和非对称加密 1.单向加密算法 单向加密算法主要用来验证数据传输的过程中,是否被篡改过. BASE64 严格地说,属 ...
- 20145332 《网络攻防》 逆向与Bof实验
20145332 <网络攻防>逆向与Bof实验 实践目标 本次实践的对象是一个名为pwn1的linux可执行文件. 该程序正常执行流程是:main调用foo函数,foo函数会简单回显任何用 ...
- 20135234mqy-——信息安全系统设计基础第十周学习总结
ls1:显示当前目录下的文件. ls2:查看文件的详细信息(用户名,群组名,大小,创建时间,读写权限等). who:读取需要的信息到存储器,并用标准输出函数打印到屏幕上 filesize:计算文件的字 ...
- Codeforces Round#413 Problem A - C
Problem#A Carrot Cakes vjudge链接[here] (偷个懒,cf链接就不给了) 题目大意是说,烤面包,给出一段时间内可以考的面包数,建第二个炉子的时间,需要达到的面包数,问建 ...
- bzoj 3223 文艺平衡树 - Splay
3223: Tyvj 1729 文艺平衡树 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 3884 Solved: 2235[Submit][Sta ...
- VirtualBox 安装XP虚拟机需要注意的问题
1.首先要有xp系统的镜像文件 http://pan.baidu.com/s/1i4xrwdJ 2.新建虚拟机,并安装 http://www.pczhishi.cn/shipin/107.html 3 ...
- Django组件(四) Django之Auth模块
Auth模块概述 Auth模块是Django自带的用户认证模块: 我们在开发一个网站的时候,无可避免的需要设计实现网站的用户系统.此时我们需要实现包括用户注册.用户登录.用户认证.注销.修改密码等功能 ...
- 高通RFC适配RFFE-添加MIPI设备【转】
本文转载自:https://blog.csdn.net/u011212816/article/details/80828625 RF driver主要设计到的器件 1.Transceiver 2.RF ...
- 试着用React写项目-利用react-router解决跳转路由等问题(三)
转载请注明出处:王亟亟的大牛之路 本来想一下子把路由的接下来的内容都写完的,但是今天白天开了会,传了些代码打了个包,就被耽搁了 这一篇来讲一下 IndexLink和 onlyActiveOnIndex ...
- [BZOJ2963][JLOI2011]飞行路线 分层图+spfa
Description Alice和Bob现在要乘飞机旅行,他们选择了一家相对便宜的航空公司.该航空公司一共在n个城市设有业务,设这些城市分别标记为0到n-1,一共有m种航线,每种航线连接两个城市,并 ...