title: How to create Trigger Object Programmatically?
body: <p>I am using Spring quartz Scheduler but I am not using an XML file. I want to create the entire configuration programmatically.</p>
  
  <p>I have written the following code.</p>
  
  <pre><code>package com.eaportal.service.impl;
  
  import java.text.ParseException;
  import java.util.Date;
  import java.util.HashMap;
  import java.util.Map;
  
  import org.quartz.JobDetail;
  import org.springframework.scheduling.SchedulingException;
  import org.springframework.scheduling.quartz.CronTriggerBean;
  import org.springframework.scheduling.quartz.JobDetailBean;
  import org.springframework.scheduling.quartz.SchedulerFactoryBean;
  
  import com.eaportal.service.intfc.AuctionWinnerService;
  
  public class NormalAuctionWinnerServiceImpl1 implements AuctionWinnerService {
  
      @SuppressWarnings("deprecation")
      public void declareWinner(int auctionId, Map&lt;String, Object&gt; parameterMap) {
          System.out.println("INSIDE DECLARE WINNER METHOD.");
          /** STEP 1 : INSTANTIATE TASK CLASS **/
          NormalAuctionWinnerTask1 runMeTask = new NormalAuctionWinnerTask1();
          System.out.println("FINISHED STEP 1");
  
          /** STEP 2 : INSTANTIATE JOB DETAIL CLASS AND SET ITS PROPERTIES **/
          Map&lt;String,Object&gt; jobDataAsMap = new HashMap&lt;String,Object&gt;();
          jobDataAsMap.put("runMeTask",runMeTask);
          JobDetailBean jdb = new JobDetailBean();
          jdb.setJobClass(NormalAuctionWinnerTask1.class);
          jdb.setJobDataAsMap(jobDataAsMap);
          System.out.println("FINISHED STEP 2");
  
          /** STEP 3 : INSTANTIATE CRON TRIGGER AND SET ITS PROPERTIES **/
          CronTriggerBean ctb = new CronTriggerBean();
          Date d1 = new Date();
          Date d2 = new Date();
          d2.setMinutes(d1.getMinutes()+10);
          ctb.setStartTime(d1);
          ctb.setEndTime(d2);
          ctb.setJobDetail(jdb);
  
          try {
              ctb.setCronExpression("59 * * * * ? *");
          } catch (ParseException e) {
              e.printStackTrace();
          }
  
          /** STEP 4 : INSTANTIATE SCHEDULER FACTORY BEAN AND SET ITS PROPERTIES **/
          SchedulerFactoryBean sfb = new SchedulerFactoryBean();
          sfb.setJobDetails(new JobDetail[]{jdb});
          try {
              sfb.start();
          } catch (SchedulingException e) {
              e.printStackTrace();
          }
      }
  
  }
  </code></pre>
  
  <p>The code is working except the trigger doesn't fire coz I haven't set it.</p>
  
  <p>Here the problem is in XML configuration we have 'triggers' property of schedulerFactoryBean and we use list to configure our triggers.</p>
  
  <p>But I am not able to set the same property programmatically.
  There is a setTriggers method in SchedulerFactoryBean that accepts an array of Trigger
  but how to create it is the problem.</p>
  
  <p>I am on it for the last 4 hrs still no sign of success.</p>
  
  <p>Can someone help me here?</p>
  
  <p>Thanks</p>