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