Java 如何覆盖quartz';s属性值
我有spring启动应用程序及其application.properties文件。该项目依赖于第三方库,在我的例子中是:Java 如何覆盖quartz';s属性值,java,spring,spring-boot,quartz-scheduler,Java,Spring,Spring Boot,Quartz Scheduler,我有spring启动应用程序及其application.properties文件。该项目依赖于第三方库,在我的例子中是: <dependency> <groupId>org.quartz-scheduler</groupId> <artifactId>quartz</artifactId> <version>2.3.0</version> </dependency> 要有另一
<dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz</artifactId>
<version>2.3.0</version>
</dependency>
要有另一个线程数
如何使用自己的属性文件和/或环境变量执行此操作?您可以通过创建自己的属性解析器来覆盖此值:
@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
在这里您可以查看代码示例
使用Spring boot 2应用程序(假设您有Spring boot starter quartz),您可以直接指定属性: 春天: 石英: 特性: org.quartz.threadPool.threadCount:10 石英调度器配置可以通过使用石英配置属性()spring.Quartz.properties.*)和SchedulerFactoryBeanCustomizer bean进行自定义,这允许编程SchedulerFactoryBean自定义
#============================================================================
# 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