How to make sure quartz.properties is being used?
For those who are using Spring + Quartz and quartz.properties
file is not working (i.e. gets ignored while starting the application):
Quartz Scheduler (org.quartz.Scheduler
) instantiated by Spring Factory Bean (org.springframework.scheduling.quartz.SchedulerFactoryBean
) won't read quartz.properties
file from the classpath by default as it's said in Quartz docs - you need to set the reference manually:
[in case of Java config]:
@Bean
public SchedulerFactoryBean schedulerFactoryBean() {
SchedulerFactoryBean schedulerFactoryBean = new SchedulerFactoryBean();
schedulerFactoryBean.setConfigLocation(new ClassPathResource("quartz.properties"));
// ...
}
[in case of XML config]:
<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="configLocation" value="classpath:quartz.properties" />
// ...
</bean>
oops, I found the problem, actually the code was overriding the properties file config by creating an instance of Properties class in the code. so the answer is this line:
sf = new StdSchedulerFactory("conf/quartz.properties");