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

  • 相关阅读:
    composer
    brew转为国内源
    轻松生成一个golang的docker应用程序
    轻松生成一个vue的静态nginx
    【OS_Windows】windows server设置多用户可同时远程连接
    【OS_Linux】centos中查看已有用户信息
    【OS_Linux】查看Linux系统版本的命令
    【OS_Linux】借助终端Xshell实现Centos文件的上传与下载
    【OS_Linux】终端XShell的安装与使用
    【OS_Linux】VMware 中安装CentOS7
  • 原文地址:https://www.cnblogs.com/danghuijian/p/6829932.html
Copyright © 2011-2022 走看看