【Quartz】SpringBoot使⽤properties⽂件配置Quartz (1)在resource⽬录下新建quartz.properties⽂件
#============================================================================
# 基础配置
#============================================================================
org.quartz.scheduler.instanceName = JobScheduler
org.quartz.scheduler.instanceId = AUTO
org.i.export = false
org.i.proxy = false
org.quartz.scheduler.wrapJobExecutionInUserTransaction = false
#============================================================================
# 调度器线程池配置
#============================================================================
org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool
org.quartz.threadPool.threadCount = 20
org.quartz.threadPool.threadPriority = 5
org.quartz.jobStore.misfireThreshold = 60000
#============================================================================
# Configure JobStore 作业存储配置
#============================================================================
org.quartz.jobStore.class = org.quartz.impl.jdbcjobstore.JobStoreTX
org.quartz.jobStore.driverDelegateClass = org.quartz.impl.jdbcjobstore.StdJDBCDelegate
org.quartz.jobStore.useProperties = true
org.quartz.jobStore.tablePrefix = QRTZ_
aptana macorg.quartz.jobStore.dataSource = qzDS
org.quartz.jobStore.isClustered = true
org.quartz.jobStore.clusterCheckinInterval = 15000
#============================================================================
# JDBC
#============================================================================
org.quartz.dataSource.qzDS.driver = sql.jdbc.Driver
org.quartz.dataSource.qzDS.URL = jdbc:mysql://localhost:3306/job_scheduler?useUnicode=true&characterEncoding=UTF-8&useSSL=false
org.quartz.dataSource.qzDS.user = ****************
shelly和sherryorg.quartz.dataSource.qzDS.password = **************
org.quartz.dataSource.qzDS.maxConnections = 5
org.quartz.dataSource.qzDS.validationQuery = select 0 from dual
关于quartz配置的详情,参见。
(2) 写配置解析类
1import org.quartz.Scheduler;
2import servlet.QuartzInitializerListener;
3import org.springframework.fig.PropertiesFactoryBean;
4import t.annotation.Bean;
5import t.annotation.Configuration;
6import io.ClassPathResource;
7import org.springframework.scheduling.quartz.SchedulerFactoryBean;
8import pt.Crypter;
9import pt.CrypterFactory;
10
11import java.io.IOException;
12import java.util.Properties;
13
14 @Configuration //类似xml中的<beans>标签,⼀般和@bean注解⼀起使⽤来配置⼀个Bean,让Spring来管理它的⽣命周期
15public class SchedulerConfig {
16
17    @Bean(name="SchedulerFactory")特效师属于什么专业
18public SchedulerFactoryBean schedulerFactoryBean() throws IOException {
19        SchedulerFactoryBean factory = new SchedulerFactoryBean();
20        factory.setQuartzProperties(quartzProperties());
21return factory;
22    }
23
24/**
25    * 加载Quartz配置
26    *
27*/
28    @Bean
properties文件用什么打开
29public Properties quartzProperties() throws IOException {
30//使⽤Spring的PropertiesFactoryBean对属性配置⽂件进⾏管理
31        PropertiesFactoryBean propertiesFactoryBean = new PropertiesFactoryBean();sqlyog怎么运行语句
32        propertiesFactoryBean.setLocation(new ClassPathResource("/quartz_config.properties"));
33        propertiesFactoryBean.afterPropertiesSet();
34
35        Properties properties = Object();
36
37// 账号密码解密
38        Crypter crypter = Crypter(CrypterFactory.AES_CBC);
39        String user = Property("org.quartz.dataSource.qzDS.user");
40if (user != null) {
41            user = crypter.decrypt(user);
42            properties.setProperty("org.quartz.dataSource.qzDS.user", user);
43        }
44        String password = Property("org.quartz.dataSource.qzDS.password");
45if (password != null) {
46            password = crypter.decrypt(password);
47            properties.setProperty("org.quartz.dataSource.qzDS.password", password);
48        }
49
50return properties;
51    }
52
53/**
54    * 初始化Quartz,让Spring boot启动时初始化Quartzred5实现回放功能
55    *
56*/
57    @Bean
58public QuartzInitializerListener executorListener() {
59return new QuartzInitializerListener();
60    }
61
62/**
63    * 通过SchedulerFactoryBean获取Scheduler的实例
64*/
65    @Bean(name="Scheduler")
66public Scheduler scheduler() throws IOException {
67return schedulerFactoryBean().getScheduler();
68    }
69 }
SchedulerConfig.java

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。