问题
I have spring boot application with it's application.properties file. The project has a dependency on third-party library, in my case its:
<dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz</artifactId>
<version>2.3.0</version>
</dependency>
The library has its quartz.properties file with configs. I would like to override some values, e.g.:
org.quartz.threadPool.threadCount:10
to have another number of threads.
How can I do it using my own properties file and/or environment variable?
回答1:
With Spring boot 2 application ( assuming you have the spring-boot-starter-quartz ), you can just specify the properties directly:
spring: quartz: properties: 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.
回答2:
You can override this value creating your own property resolver:
@Bean
public Properties quartzProperties() throws IOException {
PropertiesFactoryBean propertiesFactoryBean = new PropertiesFactoryBean();
propertiesFactoryBean.setLocation(new ClassPathResource("/quartz.properties"));
propertiesFactoryBean.afterPropertiesSet();
return propertiesFactoryBean.getObject();
}
And in your 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
Here you can check code example.
https://www.quickprogrammingtips.com/spring-boot/spring-boot-quartz-scheduler-integration.html
https://gist.github.com/cardosomarcos/149f915b966f7bb132f436dae5af1521
来源:https://stackoverflow.com/questions/51984244/how-to-override-quartzs-property-value