美文网首页
QuartzConfigration

QuartzConfigration

作者: 牧祎徉 | 来源:发表于2020-04-27 23:06 被阅读0次

package com.cg.vboot.common.config;

import java.io.IOException;

import java.util.Properties;

import com.cg.vboot.common.quartz.factory.JobFactory;

import org.quartz.Scheduler;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.beans.factory.config.PropertiesFactoryBean;

import org.springframework.context.annotation.Bean;

import org.springframework.context.annotation.Configuration;

import org.springframework.core.io.ClassPathResource;

import org.springframework.scheduling.quartz.SchedulerFactoryBean;

@Configuration

public class QuartzConfigration {

@Autowired

JobFactory jobFactory;

@Bean

public SchedulerFactoryBean schedulerFactoryBean() {

SchedulerFactoryBean schedulerFactoryBean = new SchedulerFactoryBean();

try {

schedulerFactoryBean.setOverwriteExistingJobs(true);

schedulerFactoryBean.setQuartzProperties(quartzProperties());

schedulerFactoryBean.setJobFactory(jobFactory);

} catch (IOException e) {

e.printStackTrace();

}

return schedulerFactoryBean;

}

// 指定quartz.properties

@Bean

public Properties quartzProperties() throws IOException {

PropertiesFactoryBean propertiesFactoryBean = new PropertiesFactoryBean();

propertiesFactoryBean.setLocation(new ClassPathResource("/config/quartz.properties"));

propertiesFactoryBean.afterPropertiesSet();

return propertiesFactoryBean.getObject();

}

// 创建schedule

@Bean(name = "scheduler")

public Scheduler scheduler() {

return schedulerFactoryBean().getScheduler();

}

}

相关文章

网友评论

      本文标题:QuartzConfigration

      本文链接:https://www.haomeiwen.com/subject/xwwpwhtx.html