Spring4.2.4和quartz2.2.3整合定时任务
来源:互联网 发布:知乎 电钢琴 编辑:程序博客网 时间:2024/05/19 01:09
平常工作中也有接触到定时任务,刚刚接触时自己也是在网上学习了一下。然后今天想记录下来我的。
定时任务类:
public class TaskTest {public void print(){String time = DateFormat.getDateTimeInstance().format(new Date()); System.out.println("定时器触发打印--print"+time);} }
applicationContext.xml配置:
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:task="http://www.springframework.org/schema/task" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.2.xsd" default-lazy-init="false"> <!-- 配置任务bean类 --> <bean id="TaskTest" class="timeTask.TaskTest"></bean> <!-- 配置方法映射工厂类 --><bean id="jobDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"> <property name="targetObject" ref="TaskTest"></property> <property name="targetMethod" value="print"></property> <property name="concurrent" value="false"></property> <!-- concurrent : false表示等上一个任务执行完后再开启新的任务 --></bean> <!-- 配置任务高度的的时间/周期 --><bean id="billsCheckJobTrigger" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean"> <property name="jobDetail" ref="jobDetail"></property> <property name="cronExpression" value="0/5 * * * * ?"></property> </bean><!-- 调度工厂 --><bean id="schedulerFactoryBean" class="org.springframework.scheduling.quartz.SchedulerFactoryBean"> <property name="triggers"> <list> <ref bean="billsCheckJobTrigger"/> </list> </property> </bean> </beans>
web.xml配置如下:
<?xml version="1.0" encoding="UTF-8"?><web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"> <display-name></display-name> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/applicationContext.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener></web-app>
jar包结构:
然后Tomcat加载项目并且运行项目,控制台输出如下:
阅读全文
1 0
- Spring4.2.4和quartz2.2.3整合定时任务
- Spring4整合Quartz2实现定时任务
- Spring4整合quartz2.3,集群定时任务处理
- spring4+ Quartz2普通定时任务
- Spring4 Quartz2 动态任务,Spring4整合quartz2.2.3简单动态任务
- Spring定时任务,Spring4整合quartz2.2,quartz-scheduler定时任务
- Spring 和Quartz2 整合实现动态定时任务
- quartz2.2.1和spring4.1.4整合使用
- spring4和quartz2.x整合,对任务做动态操作(增删改查)
- spring4 quart定时任务整合
- spring4+ Quartz2动态任务
- spring4.2.2+quartz2.2.1整合
- Spring4+Quartz2计划任务集群
- Spring4.0整合Quartz实现定时任务
- Spring4.0.1+Quartz2.2.1实现定时任务调度[亲测可用]
- spring4整合quartz2.x集群配置,并实现任务计数功能
- Spring4整合Quartz2(Maven Demo)
- Spring4+Quartz2集群动态创建任务
- 求二叉树的所有结点之和,Python实现
- 欢迎使用CSDN-markdown编辑器
- java实现全排列
- 最简单的php操作MySQL数据库
- H264参数结构三:序列参数集层(SPS) & 图像参数集语义
- Spring4.2.4和quartz2.2.3整合定时任务
- 第12章 模板与STL
- disabled 之后样式恢复
- session相关整理
- 织梦CMS 文章详情报错—你会看到这个提示,那是因为你的系统无法识别某栏目的模型信息,或者你新建模型后.....
- 线程使用方法总结
- Java使用Redis代码示例
- Vcpkg安装指南
- 文件的异步上传