This week's book giveaway is in the JavaFX forum.
We're giving away four copies of Introducing JavaFX 8 Programming and have Herbert Schildt on-line!
See this thread for details.
The moose likes Spring and the fly likes Spring quatrz dynamic cron expression Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Introducing JavaFX 8 Programming this week in the JavaFX forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Spring quatrz dynamic cron expression" Watch "Spring quatrz dynamic cron expression" New topic

Spring quatrz dynamic cron expression

francis varkey
Ranch Hand

Joined: Sep 13, 2005
Posts: 169
Hi ,
I am trying to implement a scheduler using quartz in spring3. The requirement is need to take value of cron expression should read from database. While trying this I am getting following exception.

Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cronTrigger' defined in class path resource [Spring-Quartz.xml]: Cannot resolve reference to bean 'constructCronExpression' while setting bean property 'cronExpression'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'constructCronExpression' is defined


1) Spring-Quartz.xml

<beans xmlns=""

<bean id="runMeTask" class="test.RunMeTask" />
<!-- <bean id="constructCronExpression" class="test.CustomCronExpression" /> -->

<!-- Spring Quartz -->
<bean name="runMeJob" class="org.springframework.scheduling.quartz.JobDetailBean">

<property name="jobClass" value="test.RunMeJob" />

<property name="jobDataAsMap">
<entry key="runMeTask" value-ref="runMeTask" />


<bean id="runMeJob"
<property name="targetObject" ref="runMeTask" />
<property name="targetMethod" value="printMe" />

<!-- Simple Trigger, run every 5 seconds -->
<bean id="simpleTrigger"

<property name="jobDetail" ref="runMeJob" />
<property name="repeatInterval" value="5000" />
<property name="startDelay" value="1000" />


<!-- Cron Trigger, run every 5 seconds -->
<bean id="cronTrigger"

<property name="jobDetail" ref="runMeJob" />
<!-- <property name="cronExpression" value="0/5 * * * * ?" /> -->
<property name="cronExpression" ref="constructCronExpression"/>


<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="jobDetails">
<ref bean="runMeJob" />

<property name="triggers">
<ref bean="simpleTrigger" />


package test;

public class RunMeTask {
public void printMe() {
System.out.println("Spring 3 + Quartz 1.8.6 ~");

package test;

import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.scheduling.quartz.QuartzJobBean;

public class RunMeJob extends QuartzJobBean {
private RunMeTask runMeTask;

public void setRunMeTask(RunMeTask runMeTask) {
this.runMeTask = runMeTask;

protected void executeInternal(JobExecutionContext context)
throws JobExecutionException {



package test;


public class App
public static void main( String[] args ) throws Exception
new ClassPathXmlApplicationContext("Spring-Quartz.xml");

package test;
import org.springframework.context.annotation.Bean;

import org.springframework.context.annotation.Configuration;

public class CustomCronExpression{

public String constructCronExpression() {
String cronExpression = "0/5 * * * * ?"; //Contruct Cron Expression from the request
return cronExpression ;


Thank You

I agree. Here's the link:
subject: Spring quatrz dynamic cron expression
It's not a secret anymore!