2 changed files with 97 additions and 96 deletions
@ -1,64 +1,64 @@ |
|||||
package com.ccsens.scheduler.config; |
//package com.ccsens.scheduler.config;
|
||||
|
//
|
||||
import cn.hutool.core.io.resource.ClassPathResource; |
//import cn.hutool.core.io.resource.ClassPathResource;
|
||||
import org.quartz.Scheduler; |
//import org.quartz.Scheduler;
|
||||
import org.quartz.ee.servlet.QuartzInitializerListener; |
//import org.quartz.ee.servlet.QuartzInitializerListener;
|
||||
import org.springframework.beans.factory.config.PropertiesFactoryBean; |
//import org.springframework.beans.factory.config.PropertiesFactoryBean;
|
||||
import org.springframework.context.annotation.Bean; |
//import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration; |
//import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.scheduling.quartz.SchedulerFactoryBean; |
//import org.springframework.scheduling.quartz.SchedulerFactoryBean;
|
||||
|
//
|
||||
import java.io.IOException; |
//import java.io.IOException;
|
||||
import java.util.Properties; |
//import java.util.Properties;
|
||||
|
//
|
||||
/** |
///**
|
||||
* @description: |
// * @description:
|
||||
* @author: whj |
// * @author: whj
|
||||
* @time: 2021/6/30 15:48 |
// * @time: 2021/6/30 15:48
|
||||
*/ |
// */
|
||||
@Configuration |
//@Configuration
|
||||
public class SchedulerConfig { |
//public class SchedulerConfig {
|
||||
/** |
// /**
|
||||
* 读取quartz.properties 文件 |
// * 读取quartz.properties 文件
|
||||
* 将值初始化 |
// * 将值初始化
|
||||
* @return |
// * @return
|
||||
*/ |
// */
|
||||
@Bean |
// @Bean
|
||||
public Properties quartzProperties() throws IOException { |
// public Properties quartzProperties() throws IOException {
|
||||
PropertiesFactoryBean propertiesFactoryBean = new PropertiesFactoryBean(); |
// PropertiesFactoryBean propertiesFactoryBean = new PropertiesFactoryBean();
|
||||
propertiesFactoryBean.setLocation(new ClassPathResource("/quartz.properties")); |
// propertiesFactoryBean.setLocation(new ClassPathResource("/quartz.properties"));
|
||||
propertiesFactoryBean.afterPropertiesSet(); |
// propertiesFactoryBean.afterPropertiesSet();
|
||||
return propertiesFactoryBean.getObject(); |
// return propertiesFactoryBean.getObject();
|
||||
} |
// }
|
||||
|
//
|
||||
/** |
// /**
|
||||
* 将配置文件的数据加载到SchedulerFactoryBean中 |
// * 将配置文件的数据加载到SchedulerFactoryBean中
|
||||
* @return |
// * @return
|
||||
* @throws IOException |
// * @throws IOException
|
||||
*/ |
// */
|
||||
@Bean |
// @Bean
|
||||
public SchedulerFactoryBean schedulerFactoryBean() throws IOException { |
// public SchedulerFactoryBean schedulerFactoryBean() throws IOException {
|
||||
SchedulerFactoryBean schedulerFactoryBean = new SchedulerFactoryBean(); |
// SchedulerFactoryBean schedulerFactoryBean = new SchedulerFactoryBean();
|
||||
schedulerFactoryBean.setQuartzProperties(); |
// schedulerFactoryBean.setQuartzProperties();
|
||||
return schedulerFactoryBean; |
// return schedulerFactoryBean;
|
||||
} |
// }
|
||||
|
//
|
||||
/** |
// /**
|
||||
* 初始化监听器 |
// * 初始化监听器
|
||||
* @return |
// * @return
|
||||
*/ |
// */
|
||||
@Bean |
// @Bean
|
||||
public QuartzInitializerListener executorListener(){ |
// public QuartzInitializerListener executorListener(){
|
||||
return new QuartzInitializerListener(); |
// return new QuartzInitializerListener();
|
||||
} |
// }
|
||||
|
//
|
||||
/** |
// /**
|
||||
* 获得Scheduler 对象 |
// * 获得Scheduler 对象
|
||||
* @return |
// * @return
|
||||
* @throws IOException |
// * @throws IOException
|
||||
*/ |
// */
|
||||
@Bean |
// @Bean
|
||||
public Scheduler scheduler() throws IOException { |
// public Scheduler scheduler() throws IOException {
|
||||
return schedulerFactoryBean().getScheduler(); |
// return schedulerFactoryBean().getScheduler();
|
||||
} |
// }
|
||||
} |
//}
|
||||
|
|||||
Loading…
Reference in new issue