定时任务quartz
pom引入
<dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz</artifactId>
<version>1.8.6</version>
</dependency>
配置文件xml中引入
<!--配置schedule -->
<import resource="classpath:context/schedule/schedule-center.xml" />
<!--例子 -->
<import resource="classpath:context/schedule/schedule-syncTeamName-config.xml"/>
<!--配置properties文件 -->
<import resource="classpath:context/envPropertyLoader.xml" />
schedule-center.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:jee="http://www.springframework.org/schema/jee"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
http://www.springframework.org/schema/jee
http://www.springframework.org/schema/jee/spring-jee-2.5.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd"
default-lazy-init="false">
<!-- 总管理类 如果将lazy-init='false'那么容器启动就会执行调度程序 -->
<bean id="schedulerFactory" lazy-init="false" autowire="no"
class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref bean="tp-schedule.syncTeamNameTrigger" />
</list>
</property>
</bean>
</beans>
envPropertyLoader.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="configBean" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:/properties/tp-schedule.properties</value>
</list>
</property>
</bean>
</beans>
schedule-syncTeamName-config.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:jee="http://www.springframework.org/schema/jee"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
http://www.springframework.org/schema/jee
http://www.springframework.org/schema/jee/spring-jee-2.5.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd"
default-lazy-init="false">
<!-- 定义触发时间 -->
<bean id="tp-schedule.syncTeamNameTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail">
<ref bean="syncTeamNameJob" />
</property>
<!-- cron表达式 -->
<property name="cronExpression">
<value>${tp-schedule.SYNCTEAMNAMEJOB}</value>
<!--properties文件 tp-schedule.SYNCTEAMNAMEJOB= 0 0 15 ? * FRI -->
</property>
</bean>
<!-- 定义调用对象和调用对象的方法 -->
<bean id="syncTeamNameJob" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean" >
<!-- 调用的类 -->
<property name="targetObject">
<ref bean="syncTeamNameJobExecutor" />
</property>
<!-- 调用类中的方法 -->
<property name="targetMethod">
<value>execute</value>
</property>
</bean>
<!-- 入口程序 init-method="execute" 容器启动自动执行一次-->
<bean id="syncTeamNameJobExecutor" class="com.bill99.qamp.schedule.syncTeamNameJobExecutor" init-method="execute">
<property name="iBdf2DeptServiceImpl" ref="iBdf2DeptServiceImpl" />
</bean>
</beans>
syncTeamNameJobExecutor
public class syncTeamNameJobExecutor {
private Logger logger = Logger.getLogger(this.getClass());
private IBdf2DeptService iBdf2DeptServiceImpl;
public void execute(){
logger.info("**-----开始同步TeamName");
iBdf2DeptServiceImpl.insertbdf2dept();
logger.info("**-----同步TeamName完成");
}
public void setiBdf2DeptServiceImpl(IBdf2DeptService iBdf2DeptServiceImpl) {
this.iBdf2DeptServiceImpl = iBdf2DeptServiceImpl;
}
}
定时任务quartz的更多相关文章
- spring学习总结(mybatis,事务,测试JUnit4,日志log4j&slf4j,定时任务quartz&spring-task,jetty,Restful-jersey等)
在实战中学习,模仿博客园的部分功能.包括用户的注册,登陆:发表新随笔,阅读随笔:发表评论,以及定时任务等.Entity层设计3张表,分别为user表(用户),essay表(随笔)以及comment表( ...
- spring多个定时任务quartz配置
spring多个定时任务quartz配置 <?xml version=”1.0″ encoding=”UTF-8″?> <beans xmlns=”http://www.spring ...
- Java生鲜电商平台-定时器,定时任务quartz的设计与架构
Java生鲜电商平台-定时器,定时任务quartz的设计与架构 说明:任何业务有时候需要系统在某个定点的时刻执行某些任务,比如:凌晨2点统计昨天的报表,早上6点抽取用户下单的佣金. 对于Java开源生 ...
- 集群服务器+定时任务(Quartz) 重复执行的问题
x StackExchange.Redis private readonly IDatabase _db; string key = string.Concat("{自己命名的Redis前缀 ...
- spring -boot定时任务 quartz 基于 MethodInvokingJobDetailFactoryBean 实现
spring 定时任务 quartz 基于 MethodInvokingJobDetailFactoryBean 实现 依赖包 如下 <dependencies> <depende ...
- (4) Spring中定时任务Quartz集群配置学习
原 来配置的Quartz是通过spring配置文件生效的,发现在非集群式的服务器上运行良好,但是将工程部署到水平集群服务器上去后改定时功能不能正常运 行,没有任何错误日志,于是从jar包.JDK版本. ...
- Spring框架下的定时任务quartz框架的使用
手头的这个项目需要用到定时任务,但之前没接触过这东西,所以不太会用,从网上找资料,大致了解了一下,其实也不难.Java的定时任务实现有三种,一种是使用JDK自带的Timer那个类来实现,另一种是使用q ...
- Spring Scheduler定时任务 + Quartz
原文地址: https://blog.csdn.net/revitalizing/article/details/61420556 版权声明:本文为博主原创文章,未经博主允许不得转载. https:/ ...
- 定时任务quartz与spring的集成
我想要在spring的集成框架中使用spring , 暂时采用quartz 根据下面的几篇博客实现了(懒得说了,直接丢链接): Quartz实现动态定时任务 Spring 3整合Quartz 2实现定 ...
- 动态添加定时任务-quartz定时器
Quartz动态添加.修改和删除定时任务 在项目中有一个需求,需要灵活配置调度任务时间,刚开始用的Java自带的java.util.Timer类,通过调度一个java.util.TimerTask任务 ...
随机推荐
- csp-s模拟测试「9.14」A·B·C(三分,贪心)
博客大概咕了很久了......... T1 A 大概推下式子就好了,考试时数据点分治DFS前30点T了,然后后70分因为两数相乘爆long long然后本来可以A掉,就WA零了....... 式子推出 ...
- 如何基于MindSpore实现万亿级参数模型算法?
摘要:近来,增大模型规模成为了提升模型性能的主要手段.特别是NLP领域的自监督预训练语言模型,规模越来越大,从GPT3的1750亿参数,到Switch Transformer的16000亿参数,又是一 ...
- uniapp 打包IOS 更新AppStore版本
Hello 你好,我是大粽子. 最近随着新版本UI的发布APP也随之更新,随之而来的也就是IOS程序提审步骤,这次我详细的截图了每一个步骤,如果你正好也需要那么跟着我的节奏一步步来肯定是没问题的. 提 ...
- 虚拟机安装Windows7旗舰版-超详细图文
虚拟机安装Windows7旗舰版 ----就是想弄一个自己用的CTF+渗透测试的工具集成系统,本来想着用真实机弄就好了,但还是出于安全的考虑,还是再装个虚拟机吧~ 1.先到MSDN找好安装包:http ...
- 关于安装运行MYSQL8.0简单使用及注意事项 On Docker Desktop & WSL2
背景介绍 MYSQL是业界非常流行的一款关系型数据库系统,关系数据库将数据保存在不同的表中,而不是将所有数据放在一个大仓库内,这样就增加了速度并提高了灵活性.MySQL所使用的SQL语言是用于访问数据 ...
- 18、linux文件属性
文件的描述信息: [root@centos6 /]# ls -lih 总用量 118K 3538945 drwxr-xr-x 3 root root 4.0K 8月 23 17:12 app 3276 ...
- 利用C语言识别用户输入字符并且输出该字符ASCII码值(大小写字母篇)(含思路)
要求:从键盘输入一个字符,如果输入字符的是小写英文字母,则将其转换为大写英文字母,然后将转换后的英文字母及其ASCII码值输出到屏幕上,如果输入的是其他字符,则不转换并且直接将它及其ASCII码值输出 ...
- 13.9示例:有理数Rational类
要点提示:java提供了表示整数和浮点数的数据类型,但是没有提供表示有理数的数据类型. public Rational extends Number implements Comparable {}
- Nginx:Nginx配置url重定向
符号含义: 正则表达式匹配: ~ 为区分大小写匹配 ~* 为不区分大小写匹配 !~和!~*分别为区分大小写不匹配及不区分大小写不匹配 文件及目录匹配: -f和!-f用来判断是否存在文件 -d和!-d用 ...
- mybatis框架学习第一天
三层架构: 表现层:用于展示数据 业务层:处理业务需求 持久层:和数据库交互的 3.持久层技术解决方案: JDBC技术: Connecction PreparedStatement ResultSet ...