3

I have a web application on Apache Tomcat. The web application uses the Quartz Scheduler. I load the quartz.properties from the classpath with the -D switch which contains the following properties:

quartz.jndi=java:comp/env/something
org.quartz.dataSource.myJndiName.jndiURL=${quartz.jndi}

But it isn't working. Maybe, the ${quartz.jndi} only works in Spring Context with the PropertyPlaceholderConfigurer bean? Is it possible to load this properties file in Spring for the Quartz Scheduler?

STW
  • 44,917
  • 17
  • 105
  • 161
user1083862
  • 31
  • 1
  • 1
  • 2

3 Answers3

9

Over a year later I know, but hopefully useful to somebody: you can accomplish this by setting the properties inside your Spring context xml:

<bean name="schedulerFactory" depends-on="flyway" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
    <property name="quartzProperties">
        <map>
            <entry key="org.quartz.threadPool.class" value="org.quartz.simpl.SimpleThreadPool" />
            <entry key="org.quartz.jobStore.useProperties" value="true" />
            <entry key="org.quartz.jobStore.class" value="org.quartz.impl.jdbcjobstore.JobStoreTX" />
            <entry key="org.quartz.jobStore.driverDelegateClass" value="org.quartz.impl.jdbcjobstore.StdJDBCDelegate" />
            <entry key="org.quartz.jobStore.tablePrefix" value="QRTZ_" />
            <entry key="org.quartz.jobStore.dataSource"  value="qzDS" />
            <entry key="org.quartz.dataSource.qzDS.jndiURL" value="java:comp/env/jdbc/${jndi.dataSource}"/>
        </map>
    </property>
    <property name="applicationContextSchedulerContextKey">
        <value>applicationContext</value>
    </property>
</bean>

Notice I've put most of the JobStore-related properties in here as they seem to need to be in the same place. There is still some other configuration in the usual quartz.properties file.

TomL
  • 759
  • 8
  • 20
  • It help me to solve the message **UpdateChecker [Quartz version update check failed: java.io.IOException:** every time the server started up. i added this `` – OJVM Jun 21 '18 at 16:02
1

You can set the configLocation in your SchedulerFactoryBean:

<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
    <property name="configLocation" value="classpath:quartz.properties" />
    [...]
</bean>
J.P. Armstrong
  • 836
  • 1
  • 9
  • 26
0

It depends what kind of Quartz property you want, there might already be a Spring-way of passing it. Generally for referring to properties entries (non Quartz-specific) pre and post Spring 3 look at this question. For Quartz-specific Spring setup and configuration have a look at the first part of the Spring scheduling documentation.

Community
  • 1
  • 1
dimitrisli
  • 20,895
  • 12
  • 59
  • 63