Configure Spring to turn Quartz scheduler on/off

This is a way to use Spring’s PropertyPlaceholderConfigurer to turn Quartz Scheduler on and off based on a properties file.

This way an application can be configurable using only the properties file exclusive of changing xml documents.

XML File:

<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="locations">
        <list>
            <value>classpath:configuration/app.properties</value>
        </list>
    </property>
    <property name="ignoreUnresolvablePlaceholders" value="true"/>
</bean>

<!-- Scheduling START -->
<bean id="chrisJobDetailBean" class="org.springframework.scheduling.quartz.JobDetailBean">
    <property name="jobClass" value="sample.springquartz.chris.chrisJob" />
    <property name="jobDataAsMap">
        <map>
            <entry key="sampleBean" value-ref="sampleBean"/>
        </map>
    </property>
</bean>

<bean id="chrisCronTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
    <property name="jobDetail" ref="chrisJobDetailBean" />
    <property name="cronExpression" value="0 0/5 * * * ?" /><!-- Fire at every 5 minutes -->
</bean>

<bean id="chrisFactory" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
    <property name="autoStartup" value="${chrisScheduler.autoStartup}"/>
    <property name="jobFactory" ref="springBeanJobFactory" />
    <property name="taskExecutor" ref="workManager" />
    <property name="triggers">
        <list>
            <ref bean="chrisCronTrigger"/>
        </list>
    </property>
</bean>

<bean id="springBeanJobFactory" class="org.springframework.scheduling.quartz.SpringBeanJobFactory"/>

<bean id="workManager"
    class="org.springframework.scheduling.commonj.WorkManagerTaskExecutor">
    <property name="workManagerName" value="wm/default" />
</bean>
<!-- Scheduling END -->

app.properties file:

chrisScheduler.autoStartup=false
 
50
Kudos
 
50
Kudos

Now read this

Notification API with Page Visibility API

When writing with Javascipt for the web, there are many APIs available for us to use. Some are very mature such as DocumentFragment while some are more experimental (yet still usable) like WebGL. In this article we combine two of these... Continue →