【Quartz】Spring Boot使用properties文件配置Quartz
(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的更多相关文章
- spring boot(5)-properties参数配置
application.properties application.properties是spring boot默认的配置文件,spring boot默认会在以下两个路径搜索并加载这个文件 s ...
- spring boot application.properties基本配置
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver spring.datasource.url=jdbc:mysql://loca ...
- Spring boot:logback文件配置
resources文件夹下:新建logback-spring.xml文件. 文件内容like: <?xml version="1.0" encoding="UTF- ...
- Spring boot 的 properties 属性值配置 application.properties 与 自定义properties
配置属性值application.properties 文件直接配置: com.ieen.super.name="MDD" 自定义properties文件配置:src/main/r ...
- 【转】spring boot application.properties 配置参数详情
multipart multipart.enabled 开启上传支持(默认:true) multipart.file-size-threshold: 大于该值的文件会被写到磁盘上 multipart. ...
- Spring boot application.properties 配置
原文链接: http://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.ht ...
- 4、Spring Boot 2.x 自动配置原理
1.4 Spring Boot 自动配置原理 简介 spring boot自动配置功能可以根据不同情况来决定spring配置应该用哪个,不应该用哪个,举个例子: Spring的JdbcTemplate ...
- Spring Boot 探索系列 - 自动化配置篇
26. Logging Prev Part IV. Spring Boot features Next 26. Logging Spring Boot uses Commons Logging f ...
- springboot(十七):使用Spring Boot上传文件
上传文件是互联网中常常应用的场景之一,最典型的情况就是上传头像等,今天就带着带着大家做一个Spring Boot上传文件的小案例. 1.pom包配置 我们使用Spring Boot最新版本1.5.9. ...
随机推荐
- 如何快速简单粗暴地理解Python中的if __name__ == '__main__'
1. 摘要 通俗的理解__name__ == '__main__':假如你叫小明.py,在朋友眼中,你是小明(__name__ == '小明'):在你自己眼中,你是你自己(__name__ == '_ ...
- 4-圆数Round Numbers(数位dp)
Round Numbers Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 14947 Accepted: 6023 De ...
- SpringMVC框架结构的图解、架构的处理流程以及三大组件的说明和使用
1.1 框架结构 1.2 架构流程 1.用户发送请求至前端控制器DispatcherServlet: 2.DispatcherServlet收到请求调用HandlerMapping处理器映射器: 3. ...
- GPS坐标转换为百度地图坐标
/** * GPS坐标转换为百度地图坐标 * 需要引入javabase64.jar 和json的一些包 * */ public class Gps2BaiDu { public static void ...
- VM参数收集(部分)
VM参数收集 -verbose:gc 输出虚拟机中GC的详细情况 -Xms20M Heap初始容量为 20M -Xmx20M Heap最大容量为 20M -XX:+HeapDumpOnOutOfMem ...
- Photoshop 原画绘制
... <伯里曼> 手绘.鼠绘和板绘.
- 面试经验之——HE集团,YZ科技
上周去了HE集团面试,该集团是做车辆辅助驾驶系统的,最终目标瞄准的是自动驾驶,加上再之前在YZ科技的面试经验,有些关于车辆驾驶上的心得想聊聊. 首先说说两个企业的面试情况吧.YZ科技中的两个技术聊天都 ...
- spring获取webapplicationcontext,applicationcontext几种方法详解(转载)
转载自 http://www.blogjava.net/Todd/archive/2010/04/22/295112.html 方法一:在初始化时保存ApplicationContext对象 代码: ...
- [label][Chrome-Extension] How to start Chrome Extension's development
Firstly , you should read these two pages. https://developer.chrome.com/extensions/overview https:/ ...
- 初尝2D骨骼动画编辑工具SPINE,并into Unity3D
一.SPINE使用 研究2D骨骼动画,CYou的朋友介绍我SPINE这个工具,开发自Esoteric Software的一款专门制作2D动画的软件,网络上的资料还很少,我这从半吊子美术技术的角度简单说 ...