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
 
69
Kudos
 
69
Kudos

Now read this

URL Encoding

Building for the web (in any language) inevitably forces you to work with URIs or a compact sequence of characters that identifies an abstract or physical resource. Or maybe each web interfacing developer works with URLs? What’s the... Continue →