quartz定时定时任务执行两次
quartz框架没问题。
流程:
sping-quartz配置
<?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:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task-4.0.xsd "> <context:annotation-config/> <task:annotation-driven/> <!-- 业务对象 -->
<bean id="testJobTask" class="com.sunyard.quartz.TestQuartzTask" />
<!-- 自动扫描包 -->
<context:component-scan base-package="com.sunyard.quartz.*" /> <!-- 定时任务start --> <!-- 调度业务 -->
<bean id="jobDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject" ref="testJobTask" />
<property name="targetMethod" value="execute" />
</bean> <!-- 增加调用的触发器,触发时间 并注入到调度工厂-->
<bean id="cronTrigger" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
<property name="jobDetail" ref="jobDetail" />
<property name="cronExpression" value="0/10 * * * * ? *" />
</bean> <!-- 设置调度工厂 注入触发器-->
<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref bean="cronTrigger" />
</list>
</property>
</bean> <!-- 定时任务end --> </beans>
之后在web.xml中
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:spring-mybatis.xml,
classpath:spring-quartz.xml
</param-value>
</context-param>
测试
/**
* 定时任务--打印测试定时任务是否成功
* @author wang
*
*/
public class TestQuartzTask{
public void execute() {
System.out.println("定时任务已启动!");
}
}
之后发现启动之后输出两行,即任务启动两次。
最终解决:
<Host appBase="" autoDeploy="true" name="localhost" unpackWARs="true">
将appBase置空即可
quartz定时定时任务执行两次的更多相关文章
- spring定时任务执行两次的原因与解决方法
spring定时任务,本地执行一次,放到服务器上后,每次执行时会执行两次,原因及解决办法. http://blog.csdn.net/yaobengen/article/details/7031266 ...
- spring学习笔记--quartz和定时任务执行
前言: 最近要写一个定时任务, 用于同步数据. 以往这种涉及数据库操作的定时脚本, 都会采用python+crontab的方式来实现. 这次画风大转, 决定试试用spring+quartz来实现一下. ...
- 关于Spring中,定时任务执行两次的解决办法
原因:如果spring-quartz.xml文件,在Spring的配置文件spring-config.xml中被加载,那么定时任务会被Spring和SpringMVC扫描两次,所以会被执行两次. 解决 ...
- spring定时任务执行两次
最近用Spring的quartz定时器的时候,发现到时间后,任务总是重复执行两次,在tomcat或jboss下都如此. 打印出他们的hashcode,发现是不一样的,也就是说,在web容器启动的时候, ...
- quartz 应用到 spring定时任务 执行两次
https://my.oschina.net/superkangning/blog/467487
- spring定时任务执行两次 项目重复初始化 项目启动两次
tomcat/config/server.xml中Host标签Context节点的问题 项目里quartz定时器总是被执行2次,通过打印发现原来项目被加载了两次,所以项目下的Listener被重复加载 ...
- spring 定时任务执行两次解决办法
在web.xml中同时配置了ContextLoaderListener和DispatcherServlet?假如真是这样的话,需要删掉一个配置,因为你相当于配置了两个spring容器,两个容器分别都执 ...
- sprint定时任务执行两次
我这里遇到的是tomcat问题,把appBase设置为空 <Host name="localhost" appBase="" unpackWARs=&qu ...
- Spring整合Quartz定时任务执行2次,Spring定时任务执行2次
Spring整合Quartz定时任务执行2次,Spring定时任务执行2次 >>>>>>>>>>>>>>>&g ...
随机推荐
- axios实现类似form传值的格式,以及实现拦截器功能,response拦截实现权限判断
import axios from 'axios' import Qs from 'qs' // 超时设置 const service = axios.create({ transformReques ...
- 每天一点点之vue框架开发 - 引入Jquery
1. 安装jquery npm install jquery --save-dev 2.在build/webpack.base.conf.js中添加如下内容 var webpack = require ...
- Android 为控件添加点击涟漪效果
Android在5.0版为Button默认添加了点击时的涟漪效果,而且在其他的控件上也可以轻松的实现这种炫酷的效果.涟漪效果可以分为两种,一种时有边界的涟漪,另一种时无边界的涟漪.所谓的有边界,即涟漪 ...
- POJ 2632:Crashing Robots
Crashing Robots Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8424 Accepted: 3648 D ...
- HDU 5282:Senior's String
Senior's String Accepts: 30 Submissions: 286 Time Limit: 2000/1000 MS (Java/Others) Memory Limit ...
- content编码
1.content有5种属性 a.content:“” //为空 b.content:attr(TItle) //可以获取当前选中标签的属性值 eg: ...
- javascript设计模式(1)——面向对象基础
用对象收编变量2种方式 1 函数式 var Object = { name:function(){ return this; }, email:function(){ return this; } } ...
- MVC学生管理系统-阶段IV(修改学生信息)
项目源码 :https://download.csdn.net/download/weixin_44718300/11091042 前期准备,主体框架, 学生列表显示 请看阶段一文章 添加学生信息 ...
- html 鼠标样式 鼠标悬停 小手样式
在style中添加cursor:pointer 实现鼠标悬停变成小手样式 先来一个示例 <div style="float:right"> <a class=&q ...
- vue实现CheckBox与数组对象绑定
实现需求: 实现一个简易的购物车,页面的表格展示data数据中的一个数组对象,并提供选中商品和全选商品checkbox复选框,页面实时显示选中商品的总金额: 分析: 1:使用v-for循环渲染arra ...