SpringBoot2集成Quartz配置独立数据源

article/2025/10/7 16:33:22

gh_1af05e953554_258.jpg

需求说明

Quartz配置需要部署独立的表结构,但是经常存于业务表之间,有些时候可能需要与业务表分开配置,所以在此给Quartz配置独立的数据源

一.版本介绍

Springboot版本为2.1.6 多数据源配置使用druid进行配置,数据库使用的为Oracle11g,如果使用的是MySQL,直接将数据库的地址和驱动改一下即可

    <parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.1.6.RELEASE</version><relativePath/></parent><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-quartz</artifactId></dependency><dependency><groupId>com.alibaba</groupId><artifactId>druid-spring-boot-starter</artifactId><version>1.1.17</version></dependency><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><optional>true</optional></dependency>

二.Quartz配置介绍

spring:datasource:type: com.alibaba.druid.pool.DruidDataSourcedriver-class-name: oracle.jdbc.driver.OracleDriverdruid:business: # 配置业务数据源url: jdbc:oracle:thin:@127.0.0.1:1521:orclusername: businesspassword: businessquartz:   #配置Quartz数据源url: jdbc:oracle:thin:@127.0.0.1:1521:orclusername: quartzpassword: quartz# 下面为连接池的补充设置,应用到上面所有数据源中# 初始化大小,最小,最大initialSize: 5minIdle: 5maxActive: 15# 配置获取连接等待超时的时间maxWait: 60000# 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒timeBetweenEvictionRunsMillis: 60000minEvictableIdleTimeMillis: 300000validationQuery: SELECT 1 FROM DUALtestWhileIdle: truetestOnBorrow: falsetestOnReturn: false# 打开PSCache,并且指定每个连接上PSCache的大小poolPreparedStatements: true# 配置监控统计拦截的filters,去掉后监控界面sql无法统计,'wall'用于防火墙maxPoolPreparedStatementPerConnectionSize: 20filters: stat,wall,log4j2# 通过connectProperties属性来打开mergeSql功能;慢SQL记录connectionProperties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000# 合并多个DruidDataSource的监控数据useGlobalDataSourceStat: trueremove-abandoned: trueremove-abandoned-timeout: 180log-abandoned: truequartz:jdbc:initialize-schema: never #配置是否每次重启项目都自动生成Quartz表结构,在此使用always生成一次后就可以改为never配置job-store-type: jdbcproperties:org:quartz:scheduler:instanceName: etlCleanSchedulerinstanceId: AUTOjobStore:class: org.quartz.impl.jdbcjobstore.JobStoreTXdriverDelegateClass: org.quartz.impl.jdbcjobstore.StdJDBCDelegatetablePrefix: QRTZ_  #Quartz表前缀isClustered: trueclusterCheckinInterval: 10000useProperties: falsethreadPool:class: org.quartz.simpl.SimpleThreadPool#线程数 一个任务使用一个线程threadCount: 100threadPriority: 5threadsInheritContextClassLoaderOfInitializingThread: true

三.配置多数据源

package com.rubikstack.etlclean.config;import com.alibaba.druid.pool.DruidDataSource;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.quartz.QuartzDataSource;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import tk.mybatis.spring.annotation.MapperScan;import javax.sql.DataSource;
import java.util.Properties;@Slf4j
@Configuration
@MapperScan(basePackages = DataSourceConfig.MAPPER_PACKAGE, sqlSessionFactoryRef = DataSourceConfig.SESSION_FACTORY)
public class DataSourceConfig {@Value("${mybatis.queryLimit}")private String queryLimit;static final String SESSION_FACTORY = "dbSqlSessionFactory";private static final String DATASOURCE_NAME = "dbDataSource";/*** mapper类的包路径*/static final String MAPPER_PACKAGE = "com.example.mapper";static final String MODEL_PACKAGE = "com.example.model";/*** 自定义mapper的xml文件路径*/private static final String MAPPER_XML_PATH = "classpath*:com.example.mapper/*Mapper.xml";/*** 数据源配置的前缀,必须与application.properties中配置的对应数据源的前缀一致*/private static final String BUSINESS_DATASOURCE_PREFIX = "spring.datasource.druid.business";private static final String QUARTZ_DATASOURCE_PREFIX = "spring.datasource.druid.quartz";@Primary@Bean(name = DATASOURCE_NAME)@ConfigurationProperties(prefix = BUSINESS_DATASOURCE_PREFIX)public DruidDataSource druidDataSource() {return new DruidDataSource();}/*** 配置Mybatis环境*/@Primary@Bean(name = SESSION_FACTORY)public SqlSessionFactory sqlSessionFactory() {log.info("配置SqlSessionFactory开始");final SqlSessionFactoryBean sessionFactoryBean = new SqlSessionFactoryBean();sessionFactoryBean.setDataSource(druidDataSource());try {PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();// 自定义mapper的xml文件地址,当通用mapper提供的默认功能无法满足我们的需求时,可以自己添加实现,与mybatis写mapper一样sessionFactoryBean.setMapperLocations(resolver.getResources(MAPPER_XML_PATH));org.apache.ibatis.session.Configuration configuration = new org.apache.ibatis.session.Configuration();Properties properties = new Properties();properties.put("queryLimit",queryLimit);configuration.setVariables(properties);configuration.setMapUnderscoreToCamelCase(true);configuration.setLogImpl(org.apache.ibatis.logging.stdout.StdOutImpl.class);sessionFactoryBean.setConfiguration(configuration);sessionFactoryBean.setTypeAliasesPackage(MODEL_PACKAGE);return sessionFactoryBean.getObject();} catch (Exception e) {log.error("配置SqlSessionFactory失败,error:{}", e.getMessage());throw new RuntimeException(e.getMessage());}}/*** @QuartzDataSource 注解则是配置Quartz独立数据源的配置*/@Bean@QuartzDataSource @ConfigurationProperties(prefix = QUARTZ_DATASOURCE_PREFIX)public DataSource quartzDataSource(){return new DruidDataSource();}
}

有关@QuartzDataSource的配置请看SpringBoot官方文档
https://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#boot-features-quartz


http://chatgpt.dhexx.cn/article/SUUrjJVb.shtml

相关文章

Quartz配置和运用详解

本文转自&#xff1a;http://topmanopensource.iteye.com/blog/1123824 最近工作需要学习quartz&#xff0c;那么必须首先了解三个概念&#xff1a; 调度器&#xff1a;负责调度作业和触发器&#xff1b; 触发器&#xff1a;设置作业执行的时间、参数、条件等&#xff1b;&…

Springboot——quartz简单配置和使用

文章目录 简单maven项目配置依赖配置编写处理类编写测试类 Springboot 项目配置依赖引入编写任务具体处理类编写配置类注意事项测试 简单maven项目配置 依赖配置 springboot项目中增加如下的quartz依赖信息&#xff1a; <!-- https://mvnrepository.com/artifact/org.qua…

Quartz配置文件quartz.properties加载

Quartz配置文件quartz.properties加载 前天&#xff0c;同事来问我&#xff0c;quatz任务调度的qurtaz.properties配置文件是如何加载的&#xff0c;项目是老大写的&#xff0c;我没看过代码&#xff0c;于是去翻了一遍源码&#xff0c;终于找到了配置的加载地方&#xff0c;让…

quartz mysql 配置_Quartz配置

1. Quartz主要配置 属性名称是否必选类型默认值说明 org.quartz.scheduler.instanceName 否 String QuartzScheduler Schedule调度器的实体名字 org.quartz.scheduler.instanceId 否 String NON_CLUSTERED Schedule调度器的实体的Id,必须唯一。 1. 当你想生成intanceId的时候可…

(AnyWhere-)安卓版“捷径”

下载 久闻酷安大名&#xff0c;下了酷安App&#xff0c;真是发现了新大陆。可以的&#xff0c;看上了AnyWhere-&#xff0c;下载试试 AnyWhere-下载地址 - 酷安 使用教程 一开始看的是这篇文章入坑的 真的不用羡慕iOS&#xff01;神奇APP“AnyWhere”让安卓也能玩“捷径” …

Anywhere,一个随启随用的静态服务器

现在用webpack也很少用到这种启动服务&#xff0c;偶尔做个小demo还是可以用用 Anywhere是一个随启随用的静态服务器&#xff0c;它可以随时随地将你的当前目录变成一个静态文件服务器的根目录。 一、首先得有node 如果没有的话&#xff0c;直接去官网下载安装包或者用brew …

Anywhere 随启随用的静态文件服务器

1.Anywhere 随启随用的静态文件服务器 ----利用nodeJs anywhere搭建本地服务器环境一&#xff1a;首先去nodeJs官网下载最新版nodeJs https://nodejs.org/en/ 安装成功后winr打开cmd 输入node -help 或者node -v查看是否安装成功 二&#xff1a;装好后输入 npm install anywhe…

快速搭建本地WebServer环境--anywhere

方式1. Nodejs anywhere 命令快速搭建 (需要nodejs环境) ● 安装anywhere包 npm install -g anywhere ● 在目录地址栏输入cmd, 打开命令提示符窗口, 输入命令 anywhere -p 8000 ● 将会自动在浏览器打开, 或者手动输入 本机ip:8000 打开 方式2. 使用 PhpStudy 软件 下载链…

如何连接到Sybase SQL Anywhere数据库

Sybase SQL Anywhere数据库具有许多非常有用的功能,与竞争对手相比,它具有很高的竞争力。首先,它允许您处理大量数据。其次,它具有很高的生产率,也就是说,可以快速提供大量数据。第三,它需要最少的管理。最后,它几乎完全自动化地集成到自定义应用程序中,不需要支持。 …

使用cors-anywhere-master 解决VUE+AXIOS跨域问题

在VUE框架中&#xff0c;用AXIOS加载微信文章&#xff0c;遇到跨域问题&#xff01; 解决方案&#xff1a; 1、去GITHUB下载 cors-anywhere-master GitHub - Rob--W/cors-anywhere: CORS Anywhere is a NodeJS reverse proxy which adds CORS headers to the proxied reques…

InstallAnywhere项目,安装开发解决方案

InstallAnywhere项目,安装开发解决方案 InstallAnywhere 是面向应用程序生产商的领先安装开发解决方案。它允许您为物理、虚拟和云环境提供一致、专业的多平台安装。您可以为本地平台(Windows、Linux、Apple、Solaris、AIX、HP-UX 和 IBM)创建可靠的安装。将现有的和新的软件产…

InstallAnywhere 2020 下载安装

InstallAnywhere 2020 InstallAnywhere 2020 提供专业且可靠的多平台安装 无论使用什么平台&#xff0c;InstallAnywhere均可使开发人员轻松创建性能相同的专业安装软件。 您将能够为Windows&#xff0c;Linux&#xff0c;Apple&#xff0c;Solaris&#xff0c;AIX&#xff0c…

Automation Anywhere视频教程

Automation Anywhere视频教程12 - 如何从CSV或文本命令读取数据1 https://www.bilibili.com/video/BV1DT4y1G7aK Automation Anywhere视频教程13 - 如何使用Excel命令&#xff08;详细信息&#xff09;1 https://www.bilibili.com/video/BV1of4y1U7Mv Automation Anywhere视频…

前端anywhere——前端应用启动服务

有时候我们在js里需要使用模块化&#xff0c;将项目打包后&#xff0c;用浏览器直接打开dist文件夹下的index.html会报错。 这个时候我们就可以安装一个 nodejs 的第三方模块&#xff1a;anywhere&#xff0c;以服务器方式打开项目。 全局安装 需要提前安装 nodejs npm inst…

nodejs服务器Anywhere使用

https://www.jianshu.com/p/3f0b7ea9df53 nodejs服务器Anywhere Anywhere是一个随启随用的静态服务器&#xff0c;它可以随时随地将你的当前目录变成一个静态文件服务器的根目录。 一&#xff0c;安装node 在nodejs官网下载&#xff0c;安装后打开cmd命令行&#xff0c;输入n…

InstallAnywhere 2022

InstallAnywhere 2022 增强的获取用户输入面板 - 高级- 在获取用户输入面板中添加了“如果必填字段为空则禁用下一步按钮”复选框选项&#xff0c;以启用/禁用通知未填写的必填字段的“下一步”按钮。 选中后&#xff0c;“获取用户输入”面板中的“下一步”按钮将被禁用&#…

pythonanywhere 如何创建虚拟环境?

本章教程介绍如何在pythonanywhere 上创建虚拟环境。 目录 1、打开控制台&#xff0c;指定python版本 2、填写你的虚拟环境路径 3、查看日志&#xff0c;安装依赖 1、打开控制台&#xff0c;指定python版本 mkvirtualenv myvirtualenv --python/usr/bin/python3.10 不指定-…

Anywhere:静态服务器的神器

Anywhere是一个静态服务器的神器&#xff0c;用它可以将dist文件放在本地跑&#xff0c;流程如下&#xff1a; 一&#xff1a;安装好了node&#xff0c;监测node安装是否成功 二&#xff1a;全局安装anywhere&#xff0c;npm install anywhere -g&#xff1b; 三、在打包好的的…

中文自动文本摘要生成指标计算,Rouge/Bleu/BertScore/QA代码实现

本部分讲述下如何计算生成摘要与参考摘要的指标&#xff0c;指标方面分为两类&#xff0c;一类基于n-grams计算&#xff0c;如Rouge-1&#xff0c;Rouge-2&#xff0c;Rouge-L&#xff0c;BLEU&#xff0c;主要衡量摘要的句法的连贯性&#xff0c;不能衡量生成摘要的真实性与忠…

相似度系列-3:传统方法ROUGE ROUGE: A Package for Automatic Evaluation of Summaries

文章目录 ROUGE: A Package for Automatic Evaluation of Summariesintroduction基础模型Rouge-NRouge_NmultiROUGE-L: Longest Common Subs equence1**Sentence-level LCS**2**Summary-Level LCS** ROUGE-W: Weighted Longest Common SubsequenceROUGE-S: Skip-Bigram Co-Occu…