cron spring boot

Posted 小樽的雨后

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了cron 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;
    }


}

 

以上是关于cron spring boot的主要内容,如果未能解决你的问题,请参考以下文章

Spring boot:thymeleaf 没有正确渲染片段

Spring boot创建定时任务

spring boot 之 spring task(定时任务)

Spring boot,jdbc 模板在手动应用程序 jar 启动后工作,但不能通过 cron。背后的原因可能是啥?

解决spring-boot启动中碰到的问题:Cannot determine embedded database driver class for database type NONE(转)(代码片段

java spring boot Schedule定时任务