Browse Source

quartz config

master
ccsens_wu 4 years ago
parent
commit
bd1da61901
  1. 128
      scheduler/src/main/java/com/ccsens/scheduler/config/SchedulerConfig.java
  2. 65
      scheduler/src/main/resources/application-dev.yml

128
scheduler/src/main/java/com/ccsens/scheduler/config/SchedulerConfig.java

@ -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();
// }
//}

65
scheduler/src/main/resources/application-dev.yml

@ -6,38 +6,39 @@ spring:
workerId: 1
datasource:
type: com.alibaba.druid.pool.DruidDataSource
quartz:
# dataSource:
# default:
# driver: com.mysql.jdbc.Driver
# URL: jdbc:mysql://localhost:3306/jobconfig?useUnicode=true&characterEncoding=utf8
# user: root
# password: 12345678
# maxConnections: 5
#相关属性配置
properties:
org:
quartz:
scheduler:
instanceName: quartzScheduler
instanceId: AUTO
jobStore:
class: org.quartz.impl.jdbcjobstore.JobStoreTX
driverDelegateClass: org.quartz.impl.jdbcjobstore.StdJDBCDelegate
tablePrefix: qrtz_
isClustered: false
clusterCheckinInterval: 10000
useProperties: false
threadPool:
class: org.quartz.simpl.SimpleThreadPool
threadCount: 10
threadPriority: 5
threadsInheritContextClassLoaderOfInitializingThread: true
#数据库方式
job-store-type: JDBC
#初始化表结构
jdbc:
initialize-schema: always
quartz:
# dataSource:
# default:
# driver: com.mysql.jdbc.Driver
# URL: jdbc:mysql://localhost:3306/jobconfig?useUnicode=true&characterEncoding=utf8
# user: root
# password: 12345678
# maxConnections: 5
#相关属性配置
properties:
org:
quartz:
scheduler:
instanceName: quartzScheduler
instanceId: AUTO
jobStore:
class: org.quartz.impl.jdbcjobstore.JobStoreTX
driverDelegateClass: org.quartz.impl.jdbcjobstore.StdJDBCDelegate
tablePrefix: QRTZ_
isClustered: false
clusterCheckinInterval: 10000
useProperties: false
threadPool:
class: org.quartz.simpl.SimpleThreadPool
threadCount: 10
threadPriority: 5
threadsInheritContextClassLoaderOfInitializingThread: true
#数据库方式
job-store-type: JDBC
#初始化表结构
jdbc:
#always never
initialize-schema: never
redis:
database: 0
host: 127.0.0.1

Loading…
Cancel
Save