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

  • 相关阅读:
    热血投篮~手机游戏图像外包,美术完成度超过80%。现在需要对部分元素进行修改,价格
    BetaTank 1.0.1 手机 游戏 Nokia Symbian 塞班
    弹弓弹球 (banus) Android 游戏
    欢迎反馈意见
    Which Macros should I use? Themida的SDK中应该怎么使用各种宏?
    通过Daffodil for VS使VS2010的IDE可以用VC6 VC7.1 VC9等编译器进行项目编译
    STL中各种容器效率
    AcceptEx获取远程ip和端口
    PC寄存器
    VC6 sp6补丁地址
  • 原文地址:https://www.cnblogs.com/danghuijian/p/6829932.html
Copyright © 2011-2022 走看看