zoukankan      html  css  js  c++  java
  • quarz spring boot

    package com.pkfare.task.manage.config;
    
    
    
    import org.quartz.spi.TriggerFiredBundle;
    import org.springframework.beans.BeansException;
    import org.springframework.context.ApplicationContext;
    import org.springframework.context.ApplicationContextAware;
    import org.springframework.context.annotation.Configuration;
    import org.springframework.scheduling.quartz.SpringBeanJobFactory;
    import org.springframework.stereotype.Component;
    
    
    @Configuration
    @Component
    public class JobBeanJobFactory extends SpringBeanJobFactory implements ApplicationContextAware {
    
        private ApplicationContext applicationContext;
    
        public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
            this.applicationContext = applicationContext;
        }
    
        @Override
        protected Object createJobInstance(TriggerFiredBundle bundle) throws Exception {
            Object jobInstance = super.createJobInstance(bundle);
            //把Job交给Spring来管理,这样Job就能使用由Spring产生的Bean了
            applicationContext.getAutowireCapableBeanFactory().autowireBean(jobInstance);
            return jobInstance;
        }
    
    
    }
    import com.pkfare.task.manage.service.impl.SelectTaskServiceImpl;
    import com.pkfare.task.manage.util.ReadConfigUtil;
    import com.pkfare.task.manage.job.MainJob;
    import org.quartz.JobDetail;
    import org.quartz.impl.triggers.CronTriggerImpl;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.beans.factory.annotation.Configurable;
    import org.springframework.context.annotation.Bean;
    import org.springframework.scheduling.quartz.SchedulerFactoryBean;
    
    import javax.sql.DataSource;
    import java.text.ParseException;
    
    import static org.quartz.JobBuilder.newJob;
    
    /**
     * Created by llq on 2016/10/28.
     */
    @Configurable
    public class QuartzConfig {
    
        @Autowired
        private JobBeanJobFactory jobBeanJobFactory;
    
        @Autowired
        SelectTaskServiceImpl selectTaskService;
    
        @Autowired
        @Bean
        public SchedulerFactoryBean SchedulerFactoryBean(DataSource dataSource) throws ParseException {
    
            SchedulerFactoryBean bean = new SchedulerFactoryBean();
            bean.setDataSource(dataSource);
    
            bean.setQuartzProperties(ReadConfigUtil.readConfig("quartz.properties"));
            bean.setSchedulerName("CRMscheduler");
            bean.setStartupDelay(3);
            bean.setApplicationContextSchedulerContextKey("applicationContextKey");
            bean.setOverwriteExistingJobs(true);
            bean.setAutoStartup(true);
            bean.setJobFactory(jobBeanJobFactory);
    
            return bean;
        }
    
    }

    http://www.blogjava.net/paulwong/archive/2014/11/14/420104.html

  • 相关阅读:
    如何在spring框架中解决多数据源的问题
    Spring动态配置多数据源
    SSH配置动态数据源
    Js操作Select大全
    SSH自定义分页标签
    兼容ie[6-9]、火狐、Chrome、opera、maxthon3、360浏览器的js本地图片预览
    Hibernate关联关系配置(一对多、一对一和多对多)
    SSH整合配置二级缓存
    CKEditor实现图片上传
    ckeditor的详细配置
  • 原文地址:https://www.cnblogs.com/danghuijian/p/6829932.html
Copyright © 2011-2022 走看看