Struts 1 + Spring 2.5.6 + Quartz 1.6 scheduler example

In this tutorial, you will integrate Struts + Spring + Quartz framework together to perform a scheduler task. Spring comes with ready solution to integrate the Struts and Quartz easily. The relationship as following :

Struts <--(Plug-In)--> Spring <--(Spring-Helper)--> Quartz <---> Scheduler task

Tools Used :

  1. Struts 1.3.10
  2. Spring 2.5.6
  3. Quartz 1.6.3

1. Scheduler Task

Create a scheduler task, and the printMessage() is the method you want to schedule.

File :

package com.mkyong.common.quartz;
public class SchedulerTask 
   public void printMessage() {
	System.out.println("Struts + Spring + Quartz integration example ~");

2. Scheduler Job

To integrate Spring with Quartz, create a SchedulerJob which extends the Spring’s QuartzJobBean, instead of the Quartz Job class.

File :

package com.mkyong.common.quartz;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.scheduling.quartz.QuartzJobBean;
public class SchedulerJob extends QuartzJobBean
	private SchedulerTask schedulerTask;
	public void setSchedulerTask(SchedulerTask schedulerTask) {
		this.schedulerTask = schedulerTask;
	protected void executeInternal(JobExecutionContext context)
	throws JobExecutionException {

3. Spring’s Quartz Helper

Spring comes with many Quartz helper classes to simplify the overall Quartz scheduler processes – Scheduler, Trigget, Job and JobDetails.

File : spring-scheduler.xml

<beans xmlns=""
  <!-- Scheduler task -->
  <bean name="schedulerTask" class="com.mkyong.common.quartz.SchedulerTask" />
   <!-- Scheduler job -->
   <bean name="schedulerJob" 
     <property name="jobClass" 
           value="com.mkyong.common.quartz.SchedulerJob" />
     <property name="jobDataAsMap">
	   <entry key="schedulerTask" value-ref="schedulerTask" />

   <!-- Cron Trigger -->
   <bean id="cronTrigger"
	<property name="jobDetail" ref="schedulerJob" />
	<property name="cronExpression" value="0/5 * * * * ?" />
   <!-- Scheduler -->
   <bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
	<property name="jobDetails">
	      <ref bean="schedulerJob" />
	<property name="triggers">
		<ref bean="cronTrigger" />

4. Struts

To integrate Spring with Struts, you need to include the Spring’s ContextLoaderPlugIn into the Struts configuration file.

File : struts-config.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC 
"-//Apache Software Foundation//DTD Struts Configuration 1.3//EN" 


   <!-- Spring Struts plugin -->
   <plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
	<set-property property="contextConfigLocation"
	value="/WEB-INF/spring-scheduler.xml" />


5. How It Works

During Struts initialization, it will start the Spring Ioc container via the Spring’s ContextLoaderPlugIn Struts plug-in; While Spring initialization, it will start the Quartz scheduled job automatically.

In this example, the printMessage() method will be executed in every 5 seconds.

Download Source Code


For more details explanation, you can reference to the following tutorials

  1. Struts + Spring integration example
  2. Spring + Quartz scheduler integration example

About the Author

author image
Founder of, love Java and open source stuff. Follow him on Twitter. If you like my tutorials, consider make a donation to these charities.


5 Comment threads
0 Thread replies
Most reacted comment
Hottest comment thread
2 Comment authors
PradeepStruts 2 + Spring 2.5.6 + Quartz scheduler integration exampleGunjan ShahSpring TutorialsStruts 2 + Quartz scheduler integration example Recent comment authors
newest oldest most voted
Struts 2 + Quartz scheduler integration example

[…] Struts + Spring + Quartz integration example Oracle Magazine (Free) Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company. […]

Spring Tutorials

[…] + Quartz scheduler example Article about how Spring schedule a job with Quartz framework.Spring + Struts + Quartz scheduler example Integrate Spring with Struts and schedule a job with Quartz framework.Integrating Spring with Other […]

Gunjan Shah
Gunjan Shah

I have implemented quartz scheduler the same way. I have used Spring 3.0.2.

But in my case the JOB is executed twice.

Here i am not able to understand How can a single thread execute the same code at same time ???

Is it a spring problem ?

Gunjan Shah,
M : 94 262 70 561.

Struts 2 + Spring 2.5.6 + Quartz scheduler integration example

[…] Struts + Spring + Quartz integration example This article is under – Struts 2.x Tutorials , Tags: Quartz , Spring , Struts2 mkyong Founder and Chief Editor of, love Java and open source stuff. Follow him on Twitter, or befriend him on Facebook or Google Plus. You might also like following tutorials : GAE TutorialsJava I/O TutorialsApache Wicket TutorialsStruts 2.x Tutorials […]


I have seen enough System.out.println on scheduler task with quartz. How do I implement real example. Like executing service registered with spring bean from SchedulerJob?