如何覆盖石英的 属性 值

How to override quartz's property value

我有 spring 引导应用程序及其 application.properties 文件。该项目依赖于第三方库,在我的例子中是:

<dependency>
    <groupId>org.quartz-scheduler</groupId>
    <artifactId>quartz</artifactId>
    <version>2.3.0</version>
</dependency>

库有其 quartz.properties 文件和配置。我想覆盖一些值,例如:

org.quartz.threadPool.threadCount:10

再增加线程数。

如何使用我自己的属性文件 and/or 环境变量来实现?

您可以覆盖此值,创建您自己的 属性 解析器:

@Bean
public Properties quartzProperties() throws IOException {
    PropertiesFactoryBean propertiesFactoryBean = new PropertiesFactoryBean();
    propertiesFactoryBean.setLocation(new ClassPathResource("/quartz.properties"));
    propertiesFactoryBean.afterPropertiesSet();
    return propertiesFactoryBean.getObject();
}

在你的 quartz.properties 中:

#============================================================================
# Configure Main Scheduler Properties
#============================================================================

org.quartz.scheduler.instanceId = AUTO
org.quartz.scheduler.threadsInheritContextClassLoaderOfInitializer = true
org.quartz.scheduler.skipUpdateCheck = true

#============================================================================
# Configure ThreadPool
#============================================================================

org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool
org.quartz.threadPool.threadCount: 20
#Thread.MAX_PRIORITY 10
org.quartz.threadPool.threadPriority: 5

#============================================================================
# Configure JobStore
#============================================================================

org.quartz.jobStore.class = org.quartz.simpl.RAMJobStore 

在这里你可以查看代码示例。

https://www.quickprogrammingtips.com/spring-boot/spring-boot-quartz-scheduler-integration.html

https://gist.github.com/cardosomarcos/149f915b966f7bb132f436dae5af1521

使用 Spring boot 2 应用程序(假设您有 spring-boot-starter-quartz ),您可以直接指定属性:

spring: 石英: 特性: org.quartz.threadPool.threadCount:10

https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-quartz.html

Quartz Scheduler configuration can be customized by using Quartz configuration properties ()spring.quartz.properties.*) and SchedulerFactoryBeanCustomizer beans, which allow programmatic SchedulerFactoryBean customization.