如何覆盖石英的属性值

时间:2018-08-23 11:00:10

标签: java spring spring-boot quartz-scheduler

我有带有它的application.properties文件的spring boot应用程序。该项目依赖于第三方库,在我的情况下是:

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

该库具有带有配置的 quartz.properties 文件。我想覆盖一些值,例如:

org.quartz.threadPool.threadCount:10

具有另一个线程数。

如何使用我自己的属性文件和/或环境变量来做到这一点?

2 个答案:

答案 0 :(得分:1)

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

春天:   石英:     特性:       org.quartz.threadPool.threadCount:10

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

  

可以使用Quartz配置属性()spring.quartz.properties。*和SchedulerFactoryBeanCustomizer bean来自定义Quartz Scheduler配置,从而可以通过编程方式对SchedulerFactoryBean进行自定义。

答案 1 :(得分:0)

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

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

在您的crystal.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