Announcement Announcement Module
Collapse
No announcement yet.
Implementation of Quartz cron job with Spring and Hibernate Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Implementation of Quartz cron job with Spring and Hibernate

    Hi,

    I am trying to learn cron job scheduler using Quartz Scheduler in one of my project.

    This is my applicationContext.xml
    Code:
     <bean class="com.cron.scheduler.InitializeJobSchedule" init-method="init">
        	    </bean>
    Inside the InitializeJobSchedule class i am initializing CronScheluder
    InitializeJobSchedule.java
    Code:
     public void init() throws ServletException {
    		 		try {
    		        	 System.out.println("Initializing NewsLetter PlugIn");
    					
    					CronScheluder objPlugin = new CronScheluder();
    					
    
    				} catch (Exception e) {
    					// TODO Auto-generated catch block
    					e.printStackTrace();
    				}
    		        	
    		}
    CronScheluder.java
    Code:
    public class CronScheluder {
    	 public CronScheluder() throws Exception {
    
    	        	 
    		 SchedulerFactory sf = new StdSchedulerFactory();
    
    	        Scheduler sche = sf.getScheduler();
    
    	        sche.start();
    
    	        JobDetail jDetail = new JobDetail("Newsletter", "NJob", ClosingStockJob.class);
    
    	        //"0 0 12 * * ?" Fire at 12pm (noon) every day
    	        //"0/2 * * * * ?" Fire at every 2 seconds every day
    
    	        CronTrigger crTrigger = new CronTrigger("cronTrigger", "NJob", "0/10 * * * * ?");
    
    	        sche.scheduleJob(jDetail, crTrigger);
    	    }
    }
    In ClosingStockJob class i am implementing one of dao(interface)
    ClosingStockJob.java
    Code:
    public class ClosingStockJob implements Job{
            @Autowired
    	@Qualifier("stockDao")
    	private StockDao stockDao;
    	
    	@Override
    	public void execute(JobExecutionContext jec) throws JobExecutionException {
    		
    		try {
    			System.out.println("Cron Executing____before");
    			stockDao.closingStockSchedular();
    		} catch (ParseException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}
             }
    }

    I am Triggering the cron scheduler daily @ 11 PM. While executing the cron scheduler i am facing NullPointerExecption in this line "stockDao.closingStockSchedular();"


    Because stockDao is null . stockDao have no object of Implementation class

    What i need to do !!!!!!

    Thank in Advance
Working...
X