码迷,mamicode.com
首页 > 编程语言 > 详细

cron spring boot

时间:2017-05-09 12:44:50      阅读:179      评论:0      收藏:0      [点我收藏+]

标签:tor   ann   super   conf   blog   管理   manage   extends   使用   

 

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;
    }


}

 

cron spring boot

标签:tor   ann   super   conf   blog   管理   manage   extends   使用   

原文地址:http://www.cnblogs.com/danghuijian/p/6829932.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!