Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
  • Quartz +Spring Integration

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 714
    Comment on it

    It seems today every application needs background jobs, here we are going to learn how to integrate Quartz Scheduler with Spring.

    Version we are using
    Spring 3.x
    Quartz 1.8.6
    Maven 3
    we have to follow few steps for configure quartz with spring
    1. Add maven depandancy in pom.xml

    <!-- Quartz framework dependencies -->  

    2..configure spring-quartz.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns=""  
     <bean id="jobs" class="com.yourpackage.Jobs" />  
                 <!--  jobs define here  -->  
     <bean id="wallFeedJob"                class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">  
          <property name="targetObject" ref="jobs" />  
          <property name="targetMethod" value="wallFeed" />  
             <!--  cron trigger define here  -->  
     <bean id="cronTriggerForWall" class="org.springframework.scheduling.quartz.CronTriggerBean">
          <property name="jobDetail" ref="wallFeedJob"/>
          <property name="cronExpression" value="0 7 12 * * ?"/>
     <!-- scheduler factory bean to bind,the executing code and time intervals together -->  
     <bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">  
          <property name="jobDetails">  
                    <ref bean="wallFeedJob" />  
          <property name="triggers">  
                   <ref bean="cronTriggerForWall"/>

    3.Write java classes for binds with quartz configuration

     public  class Jobs {
    static final Logger logger = LoggerFactory.getLogger("debugLogger");
    public void wallFeed() 
          logger.debug("wallFeed :::: "+Calendar.getInstance().getTime());
       }  }

    4.For testing you can write your main class

    public class Main {public static void main(String[] args) throws Exception {
      new ClassPathXmlApplicationContext("spring-quartz.xml");  
    1. Run code and get the output

      You can visit the following website for adjustment of time and date of job

    May be it would help.

 0 Comment(s)

Sign In

Sign up using

Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: