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

Now read this

ES6 Reflect API

This is the part of a series of blogs on the new features on the upcoming ECMAScript 6 (ES6) specification which JavaScript implements. In this blog we focus on the Reflect API introduced in ES6. Reflect Object # What is the Reflect API?... Continue →