(1)在resource目录下新建quartz.properties文件

#============================================================================
# 基础配置
#============================================================================
org.quartz.scheduler.instanceName = JobScheduler
org.quartz.scheduler.instanceId = AUTO
org.quartz.scheduler.rmi.export = false
org.quartz.scheduler.rmi.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_
org.quartz.jobStore.dataSource = qzDS org.quartz.jobStore.isClustered = true
org.quartz.jobStore.clusterCheckinInterval = 15000 #============================================================================
# JDBC
#============================================================================
org.quartz.dataSource.qzDS.driver = com.mysql.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 = ****************
org.quartz.dataSource.qzDS.password = **************
org.quartz.dataSource.qzDS.maxConnections = 5
org.quartz.dataSource.qzDS.validationQuery = select 0 from dual

关于quartz配置的详情,参见官方文档

(2) 写配置解析类

 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.core.io.ClassPathResource;
import org.springframework.scheduling.quartz.SchedulerFactoryBean;
import org.wcc.crypt.Crypter;
import org.wcc.crypt.CrypterFactory; import java.io.IOException;
import java.util.Properties; @Configuration //类似xml中的<beans>标签,一般和@bean注解一起使用来配置一个Bean,让Spring来管理它的生命周期
public class SchedulerConfig { @Bean(name="SchedulerFactory")
public SchedulerFactoryBean schedulerFactoryBean() throws IOException {
SchedulerFactoryBean factory = new SchedulerFactoryBean();
factory.setQuartzProperties(quartzProperties());
return factory;
} /**
* 加载Quartz配置
*
*/
@Bean
public Properties quartzProperties() throws IOException {
//使用Spring的PropertiesFactoryBean对属性配置文件进行管理
PropertiesFactoryBean propertiesFactoryBean = new PropertiesFactoryBean();
propertiesFactoryBean.setLocation(new ClassPathResource("/quartz_config.properties"));
propertiesFactoryBean.afterPropertiesSet(); Properties properties = propertiesFactoryBean.getObject(); // 账号密码解密
Crypter crypter = CrypterFactory.getCrypter(CrypterFactory.AES_CBC);
String user = properties.getProperty("org.quartz.dataSource.qzDS.user");
if (user != null) {
user = crypter.decrypt(user);
properties.setProperty("org.quartz.dataSource.qzDS.user", user);
}
String password = properties.getProperty("org.quartz.dataSource.qzDS.password");
if (password != null) {
password = crypter.decrypt(password);
properties.setProperty("org.quartz.dataSource.qzDS.password", password);
} return properties;
} /**
* 初始化Quartz监听器,让Spring boot启动时初始化Quartz
*
*/
@Bean
public QuartzInitializerListener executorListener() {
return new QuartzInitializerListener();
} /**
* 通过SchedulerFactoryBean获取Scheduler的实例
*/
@Bean(name="Scheduler")
public Scheduler scheduler() throws IOException {
return schedulerFactoryBean().getScheduler();
}
}

SchedulerConfig.java

【Quartz】Spring Boot使用properties文件配置Quartz的更多相关文章

  1. spring boot(5)-properties参数配置

     application.properties application.properties是spring boot默认的配置文件,spring boot默认会在以下两个路径搜索并加载这个文件 s ...

  2. spring boot application.properties基本配置

    spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver spring.datasource.url=jdbc:mysql://loca ...

  3. Spring boot:logback文件配置

    resources文件夹下:新建logback-spring.xml文件. 文件内容like: <?xml version="1.0" encoding="UTF- ...

  4. Spring boot 的 properties 属性值配置 application.properties 与 自定义properties

    配置属性值application.properties 文件直接配置: com.ieen.super.name="MDD" 自定义properties文件配置:src/main/r ...

  5. 【转】spring boot application.properties 配置参数详情

    multipart multipart.enabled 开启上传支持(默认:true) multipart.file-size-threshold: 大于该值的文件会被写到磁盘上 multipart. ...

  6. Spring boot application.properties 配置

    原文链接: http://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.ht ...

  7. 4、Spring Boot 2.x 自动配置原理

    1.4 Spring Boot 自动配置原理 简介 spring boot自动配置功能可以根据不同情况来决定spring配置应该用哪个,不应该用哪个,举个例子: Spring的JdbcTemplate ...

  8. Spring Boot 探索系列 - 自动化配置篇

    26. Logging Prev  Part IV. Spring Boot features  Next 26. Logging Spring Boot uses Commons Logging f ...

  9. springboot(十七):使用Spring Boot上传文件

    上传文件是互联网中常常应用的场景之一,最典型的情况就是上传头像等,今天就带着带着大家做一个Spring Boot上传文件的小案例. 1.pom包配置 我们使用Spring Boot最新版本1.5.9. ...

随机推荐

  1. HTTP Cookie 详解

    参考: http://blog.csdn.net/lijing198997/article/details/22174151

  2. 硬盘smart信息读取

    https://blog.csdn.net/cracker_zhou/article/details/73348966

  3. oepnni安装

    sudo apt-get install libopenni-dev libopenni2-dev / apt-get install libqhull-dev

  4. SSL握手通信详解及linux下c/c++ SSL Socket代码举例(另附SSL双向认证客户端代码)

    SSL握手通信详解及linux下c/c++ SSL Socket代码举例(另附SSL双向认证客户端代码) 摘自: https://blog.csdn.net/sjin_1314/article/det ...

  5. Android Gson 操作

    JSON序列化后的数据不带类名与名命空间,所以这两个服务端跟客户端可以不对应,需要保证字段对应即可 Asp.net MVC端 using System; using System.Collection ...

  6. Zynq学习笔记(1)——Hellow World

    Zynq是一款SOC芯片,之前只是用了PL(Programmable Logic)部分,而Zynq最突出的功能,就是内部的双核Cortex-A9,所以从现在开始我将学习ZYNQ的SOC学习(PS部分) ...

  7. Geronimo 叛逆者: 使用集成软件包:Codehaus 的 Woodstox(转载)

    XML 解析器通常是高性能.健壮应用程序的关键.传统的 XML 解析技术包括文档对象模型(Document Object Model,DOM)和 Simple API for XML (SAX).现在 ...

  8. How To Make A DFF Read Only Through Form Personalisations? (文档 ID 1289789.1)

    In this Document   Goal   Solution   References APPLIES TO: Oracle Application Object Library - Vers ...

  9. php的循环与引用的一个坑

    上代码 $arr = array( 'a'=> 'a11', 'b'=> 'b22', 'c'=> 'c33', ); foreach ($arr as $k=>&$v ...

  10. postgres数据库参数配置说明介绍

    访问 1. listen_addresses 监听访问地址 2. port 监听端口 3. max_connections 最大连接数 4. 性能 1. shared_buffers PostgreS ...