当前位置:网站首页>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 了 .
边栏推荐
- ctf [RoarCTF 2019]easy_ calc
- 防撤回测试记录
- Computer network high frequency interview questions
- Yapi cross domain request plug-in installation
- Mysql8.0 configuring my SQL in INI file_ mode=NO_ AUTO_ CREATE_ User can start
- Construction of art NFT trading platform | NFT mall
- China air compressor manufacturing market demand analysis and investment prospect research report 2022-2028
- Redis cache data consistency solution analysis
- Development prospect and investment strategic planning report of global and Chinese PVC hose industry from 2022 to 2028
- Zhimeng CMS will file a lawsuit against infringing websites
猜你喜欢

Realize video call and interactive live broadcast in the applet

win10 系统打开的软件太小,如何变大(亲测有效)

35 year old programmer fired Luna millions of assets and returned to zero in three days. Netizen: it's the same as gambling
![[Qunhui] this suite requires you to start PgSQL adapter service](/img/fb/1aea7eb833afc1a24531b612a98400.jpg)
[Qunhui] this suite requires you to start PgSQL adapter service

Zeromq from getting started to mastering

OSS CDN alicloud configuration method
![[Qunhui] import certificate](/img/1f/ab63b0556a60b98388b482d70f6156.jpg)
[Qunhui] import certificate

08_SpingBoot 集成Redis

六、项目实战---识别猫和狗

PIP batch complete uninstall package
随机推荐
CDN with OSS acceleration
Alipay failed to verify the signature (sandbox test indicates fishing risk?) [original]
Syntax error of go language generic in IDE
CTF crypto (I) some simple encoding and encryption
There is no response to redirection and jump in the laravel constructor [original]
Clickhouse stand alone installation
Double buffer technology asynchronous log system
The open software of win10 system is too small. How to make it larger (effective through personal test)
China air compressor manufacturing market demand analysis and investment prospect research report 2022-2028
Your requirements could not be resolved
Zeromq from getting started to mastering
Sixtool- source code of multi-functional and all in one generation hanging assistant
Tp6 is easy to tread [original]
Gateway can not connect to tcp://127.0.0.1: Connection refused
Be a hard worker from today on
2021-02-07
Thinkphp6 parsing QR code
Using jsup to extract images from interfaces
Mobile terminal pull-down loading pull-down loading data
Ueeditor automatically appends P tags to rich text.br tags always wrap.br tag solutions