zoukankan      html  css  js  c++  java
  • spring集成quartz

    首先需要的jar包,最好是1.8.5的,其他的版本spring如果版本不高的话,会报错

    <dependency>  
                <groupId>org.quartz-scheduler</groupId>  
                <artifactId>quartz</artifactId>  
                <version>1.8.5</version>  
    </dependency>  
    <?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:aop="http://www.springframework.org/schema/aop" 
     xmlns:context="http://www.springframework.org/schema/context" 
     xmlns:tx="http://www.springframework.org/schema/tx" 
     xsi:schemaLocation="http://www.springframework.org/schema/beans   
          http://www.springframework.org/schema/beans/spring-beans.xsd
          http://www.springframework.org/schema/aop   
          http://www.springframework.org/schema/aop/spring-aop.xsd   
          http://www.springframework.org/schema/context    
          http://www.springframework.org/schema/context/spring-context.xsd       
          http://www.springframework.org/schema/tx        
          http://www.springframework.org/schema/tx/spring-tx.xsd">
                              
            <!-- 线程执行器配置,用于任务注册 -->
            <bean id="executor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
             <property name="corePoolSize" value="10" />
             <property name="maxPoolSize" value="100" />
             <property name="queueCapacity" value="500" />
            </bean>
            
            <!-- 业务对象,自己定义的操作业务的类 -->
            <bean id="bizObject" class="com.um.framework.baseware.webadmin.modules.controller.core.ExpireJobTask" />
            
            <!-- 调度业务 -->
            <bean id="jobDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
             <property name="targetObject" ref="bizObject" />
             <property name="targetMethod" value="doBiz" />
            </bean>
            
            <!-- 调度触发器、按照时间规则触发 -->
            <bean id="cronTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
             <property name="jobDetail" ref="jobDetail" />
             <property name="cronExpression" value="* * * * * ?" />
            </bean>
            <!-- 调度触发器、按时间间隔 -->
            <bean id="taskTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerBean">
             <property name="jobDetail" ref="jobDetail" />
             <property name="startDelay" value="100" />
             <property name="repeatInterval" value="1000" />
             </bean>
             
             <!-- 设置调度 -->
            <bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
             <property name="triggers">
              <list>
               <ref bean="taskTrigger" />
               <ref bean="cronTrigger" />
              </list>
             </property>
             <property name="taskExecutor" ref="executor" />
            </bean>
    
    </beans>

    然后将该配置文件引入spring的配置文件中。下面路径根据自己实际路径

    <import resource="classpath:config/spring-context-quartzJob.xml"></import>

    java类

    package com.um.framework.baseware.webadmin.modules.controller.core;
    
    public class ExpireJobTask {
        /** Logger */
        //private static final Logger logger = LoggerFactory.getLogger(ExpireJobTask.class);
     
        /**
         * 业务逻辑处理
         */
        public void doBiz() {
            System.out.println("定时任务开启");
        }
        
    }
  • 相关阅读:
    NuGet Package Explorer使用教程下载
    .NET 大数据量并发解决方案
    ASP.NET Core 中间件 中间件(Middleware)和过滤器(Filter)的区别
    C#的dapper使用
    Quartz.NET实现作业调度
    .Net Core + DDD基础分层 + 项目基本框架 + 个人总结
    asp.net mvc框架之EF的使用
    Asp.Net MVC+EF+三层架构的完整搭建过程
    WebAPI异常捕捉处理,结合log4net日志(webapi2框架)
    SQL SERVER 2012数据库:开启防火墙导致外部无法连接数据库解决办法
  • 原文地址:https://www.cnblogs.com/guokai870510826/p/5984124.html
Copyright © 2011-2022 走看看