• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
  • Mikalai Zaikin

Spring quatrz dynamic cron expression

Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:329)


1) Spring-Quartz.xml

<beans xmlns="http://www.springframework.org/schema/beans"

<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;

import org.springframework.context.support.ClassPathXmlApplicationContext;

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

    Bookmark Topic Watch Topic
  • New Topic