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定时定时任务执行两次的更多相关文章

  1. spring定时任务执行两次的原因与解决方法

    spring定时任务,本地执行一次,放到服务器上后,每次执行时会执行两次,原因及解决办法. http://blog.csdn.net/yaobengen/article/details/7031266 ...

  2. spring学习笔记--quartz和定时任务执行

    前言: 最近要写一个定时任务, 用于同步数据. 以往这种涉及数据库操作的定时脚本, 都会采用python+crontab的方式来实现. 这次画风大转, 决定试试用spring+quartz来实现一下. ...

  3. 关于Spring中,定时任务执行两次的解决办法

    原因:如果spring-quartz.xml文件,在Spring的配置文件spring-config.xml中被加载,那么定时任务会被Spring和SpringMVC扫描两次,所以会被执行两次. 解决 ...

  4. spring定时任务执行两次

    最近用Spring的quartz定时器的时候,发现到时间后,任务总是重复执行两次,在tomcat或jboss下都如此. 打印出他们的hashcode,发现是不一样的,也就是说,在web容器启动的时候, ...

  5. quartz 应用到 spring定时任务 执行两次

    https://my.oschina.net/superkangning/blog/467487

  6. spring定时任务执行两次 项目重复初始化 项目启动两次

    tomcat/config/server.xml中Host标签Context节点的问题 项目里quartz定时器总是被执行2次,通过打印发现原来项目被加载了两次,所以项目下的Listener被重复加载 ...

  7. spring 定时任务执行两次解决办法

    在web.xml中同时配置了ContextLoaderListener和DispatcherServlet?假如真是这样的话,需要删掉一个配置,因为你相当于配置了两个spring容器,两个容器分别都执 ...

  8. sprint定时任务执行两次

    我这里遇到的是tomcat问题,把appBase设置为空 <Host name="localhost" appBase="" unpackWARs=&qu ...

  9. Spring整合Quartz定时任务执行2次,Spring定时任务执行2次

    Spring整合Quartz定时任务执行2次,Spring定时任务执行2次 >>>>>>>>>>>>>>>&g ...

随机推荐

  1. HDU - 4405 Aeroplane chess(期望dp)

    题意:沿着x轴从0走到大于等于N的某处,每一步的步数由骰子(1,2,3,4,5,6)决定,若恰好走到x轴上某飞行路线的起点,则不计入扔骰子数.问从0走到大于等于N的某处的期望的扔骰子次数. 分析: 1 ...

  2. 每天一点点之 taro 框架开发 - taro路由及传参

    1.路由 taro的路由是自带的,不需要我们额外配置,只需要我们在app.js下config中配置pages即可 class App extends Component { config = { pa ...

  3. 51nod 1429:巧克力

    1429 巧克力 题目来源: CodeForces 基准时间限制:1 秒 空间限制:131072 KB 分值: 80 难度:5级算法题  收藏  关注 现在有两个块巧克力一块大小是   的,另外一块大 ...

  4. filter滤镜兼容ie的rgba属性

    要在一个页面中设置一个半透明的白色div.这个貌似不是难题,只需要给这个div设置如下的属性即可: background: rgba(255,255,255,0.1); 但是要兼容到ie8.这个就有点 ...

  5. <强化学习>基本概念

    马尔可夫决策过程MDP,是强化学习的基础. MDP --- <S,A,P,R,γ> AGENT STATE ENV  REWARD   ,由ENV给出.agent处于状态s下,采取acti ...

  6. Python 中 使用 HTMLTestRunner 模块生成测试报告

     使用 HTMLTestRunner 模块可以生成测试报告,但是系统自带的报告不详细,不好看,所以找了一份详细的报告 HTMLTestRunner 模板,直接导入就能使用 两种方法生成HTML报告,都 ...

  7. php添加openssl扩展

    很多时候都会用到openssl组件,下面就介绍一下linux下php安装openssl扩展: 安 装openssl组件,一般php安装目录中都有许多扩展组件的安装包,当然也包括openssl,例如我的 ...

  8. 爱奇艺用券付费VIP电影+python爬虫程序+可视化界面+下载本地

    申明:本博客中的工具及源码仅供个人学习使用,请勿用作商业等其他任何违法用途!否则后果自负 直接步入正题吧! 工具开发环境:windows10,python3.6 工具界面设计:基于python 自带的 ...

  9. promise核心6 自定义promise

    1.定义整体结构(不写实现) 定义一个自己的promise的库 lib(库的简写) 一个js文件.一个js模块(不能用es6  也不能commjs)(用es5模块语法 ) 匿名函数自调用.IIFE ( ...

  10. XML--XML Schema Definition(三)

    参考 http://www.w3school.com.cn/schema/index.asp XSD 复合元素 复合元素指包含其他元素及/或属性的 XML 元素. 有四种类型的复合元素: 空元素 包含 ...