当前位置:网站首页>How to use the configured slave data source for the scheduled task configuration class scheduleconfig
How to use the configured slave data source for the scheduled task configuration class scheduleconfig
2022-06-26 04:29:00 【good writings make people copy them】
Other places are annotated with switching data sources , Solved the problem of changing the data source .
however ,scheduler The data source always uses the master data source , So the problem is ScheduleConfig, The data source is not switched successfully .
solve :
package cc.jz.quartz.config;
import cc.jz.common.enums.DataSourceType;
import cc.jz.framework.datasource.DynamicDataSourceContextHolder;
import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.quartz.SchedulerFactoryBean;
import javax.sql.DataSource;
import java.util.Properties;
/**
* Timing task configuration
*
* @author my
*/
@Configuration
public class ScheduleConfig {
@Bean
public SchedulerFactoryBean schedulerFactoryBean(@Qualifier("slaveDataSource") DataSource dataSource) {
SchedulerFactoryBean factory = new SchedulerFactoryBean();
// Set data source ( Use the system's master data source , Cover propertis Of documents dataSource To configure )
factory.setDataSource(dataSource);
// quartz Parameters
Properties prop = new Properties();
prop.put("org.quartz.scheduler.instanceName", "MyScheduler");
prop.put("org.quartz.scheduler.instanceId", "AUTO");
// Thread pool configuration
prop.put("org.quartz.threadPool.class", "org.quartz.simpl.SimpleThreadPool");
prop.put("org.quartz.threadPool.threadCount", "20");
prop.put("org.quartz.threadPool.threadPriority", "5");
// JobStore To configure
prop.put("org.quartz.jobStore.class", "org.quartz.impl.jdbcjobstore.JobStoreTX");
// Cluster configuration
prop.put("org.quartz.jobStore.isClustered", "true");
prop.put("org.quartz.jobStore.clusterCheckinInterval", "15000");
prop.put("org.quartz.jobStore.maxMisfiresToHandleAtATime", "1");
prop.put("org.quartz.jobStore.txIsolationLevelSerializable", "true");
// sqlserver Enable
// prop.put("org.quartz.jobStore.selectWithLockSQL", "SELECT * FROM {0}LOCKS UPDLOCK WHERE LOCK_NAME = ?");
prop.put("org.quartz.jobStore.misfireThreshold", "12000");
prop.put("org.quartz.jobStore.tablePrefix", "QRTZ_");
factory.setQuartzProperties(prop);
factory.setSchedulerName("JeeThinkScheduler");
// Delay start
factory.setStartupDelay(1);
factory.setApplicationContextSchedulerContextKey("applicationContextKey");
// Optional ,QuartzScheduler
// Update existing... At startup Job, In this way, you don't have to modify it every time targetObject Delete after qrtz_job_details The table records
factory.setOverwriteExistingJobs(true);
// Set auto start , The default is true
factory.setAutoStartup(true);
return factory;
}
}
When not added @Qualifier("slaveDataSource") front , Because of two data sources , The master data source is used by default . that @Qualifier("slaveDataSource") What does that mean ?
@Qualifier("slaveDataSource") Injection can be specified precisely (slaveDataSource) object
idea Development tools , When you click the red box in the figure above , You can jump directly to the data source config in :
@Bean(name = "slaveDataSource")
@ConfigurationProperties("spring.datasource.druid.slave")
@ConditionalOnProperty(prefix = "spring.datasource.druid.slave", name = "enabled", matchIfMissing = true)
public DataSource slaveDataSource(DruidProperties druidProperties) {
DruidDataSource dataSource = DruidDataSourceBuilder.create().build();
return druidProperties.dataSource(dataSource);
}
So get from the data source , Set it ok 了 .
边栏推荐
- Which is the best embedded visual programming software? (introduction, evaluation and selection of visual programming platform) [scratch, mind+, mixly]
- [Nuggets' operation routine disclosure] the routine of being truly Nuggets
- 2021/11/6-burpsuit packet capturing and web page source code modification
- Navicat connects the pit of shardingsphere sub table and sub library plug-ins
- Laravel file stream download file
- Clean up photo SCR virus / iframekill injection removal /iframekill removal photo scr
- Review of number theory
- BSC 及HT 等链的NFT 创造及绑定图片教程
- PHP has the problem of using strtotime to obtain time in months and months [original]
- Yapi cross domain request plug-in installation
猜你喜欢
Alipay failed to verify the signature (sandbox test indicates fishing risk?) [original]
[geek challenge 2019] rce me
OSS CDN alicloud configuration method
Nailing open platform - applet development practice (nailing applet client)
六、项目实战---识别猫和狗
Sorting out the examination sites of the 13th Blue Bridge Cup single chip microcomputer objective questions
PHP design function getmaxstr to find the longest symmetric string in a string - [original]
[Nuggets' operation routine disclosure] the routine of being truly Nuggets
企业的产品服务怎么进行口碑营销?口碑营销可以找人代做吗?
College C language final exam · multiple choice questions · summary notes of mistakes and difficulties
随机推荐
Install SVN in Pagoda and build SVN version Library
小程序中实现视频通话及互动直播功能
Knowledge about SQL - DML
Implementation of seven classes of BlockingQueue interface
Sixtool- source code of multi-functional and all in one generation hanging assistant
Video label forbids downloading. The test is valid. Hide button. The test is valid at three points
Nightmare
mysql自带的性能测试工具mysqlslap执行压力测试
Be a hard worker from today on
Database design (3): database maintenance and optimization
CDN with OSS acceleration
Principle and implementation of syn cookie
Review of number theory
Construction of art NFT trading platform | NFT mall
A brain map to summarize the needs analysis (a supplement to the actual situation at work)
2020-12-18
6、 Project practice --- identifying cats and dogs
Introduction to markdown grammar
Minecraft 1.16.5 biochemical 8 module 1.9 version 1.18 version synchronization
Clean up photo SCR virus / iframekill injection removal /iframekill removal photo scr