我試圖在Spring 3.2.x中使用Quartz 2.2.0,使用ServletContextListener監聽FileChangeListener類.Is我的importManagerService對象爲null?有什麼建議麼?沒有得到如何解決它在Tomcat上用Spring部署Quartz Scheduler時出現NullPointerException
錯誤在部署
INFO [2013-10-04 15:13:16.009] [localhost-startStop-1]: org.springframework.web.context.ContextLoader - Root WebApplicationContext: initialization started
ERROR [2013-10-04 15:13:16.061] [DefaultQuartzScheduler_Worker-1]: org.quartz.core.JobRunShell - Job g1.t1 threw an unhandled Exception:
java.lang.NullPointerException at
com.demo.portal.web.importExportFile.ScheduleImportFile.execute(ScheduleImportFile.java:40)
at org.quartz.core.JobRunShell.run(JobRunShell.java:207)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:560)
ERROR [2013-10-04 15:13:16.065] [DefaultQuartzScheduler_Worker-1]: org.quartz.core.ErrorLogger - Job (g1.t1 threw an exception.
org.quartz.SchedulerException: Job threw an unhandled exception. [See nested exception: java.lang.NullPointerException]
at org.quartz.core.JobRunShell.run(JobRunShell.java:218)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:560)
Caused by: java.lang.NullPointerException
at com.happiestminds.portal.web.importExportFile.ScheduleImportFile.execute(ScheduleImportFile.java:40)
at org.quartz.core.JobRunShell.run(JobRunShell.java:207)
... 1 more
FileChangeListener
public class FileChangeListener implements ServletContextListener {
private static final Logger logger = Logger.getLogger(FileChangeListener.class);
@Override
public void contextDestroyed(ServletContextEvent arg0) {
System.out.println("Stopping Application successfully");
}
@Override
public void contextInitialized(ServletContextEvent arg0) {
logger.info("Initializing Application successfully..........");
JobDetail job = JobBuilder.newJob(ScheduleImportFile.class).withIdentity("t1", "g1").build();
Trigger trigger = TriggerBuilder.newTrigger().withIdentity("trigger1", "g1").startNow()
.withSchedule(SimpleScheduleBuilder.simpleSchedule().withIntervalInSeconds(60).repeatForever()).forJob("t1", "g1").build();
SchedulerFactory schFactory = new StdSchedulerFactory();
Scheduler sch;
try {
sch = schFactory.getScheduler();
sch.start();
sch.scheduleJob(job, trigger);
} catch (SchedulerException e) {
e.printStackTrace();
}
}
}
ScheduleImportFile
**public class ScheduleImportFile implements Job{
@Autowired
ImportManagerService importManagerService;
@Override
public void execute(JobExecutionContext arg0) throws JobExecutionException {
//some logic for reading and parsing files
Line no. 40
Map<String, List<File>> fileToBeProcessMap = importManagerService.getFilesInfo(config);
Config is object of Configuration class
}**
的web.xml
<listener>
<listener-class>com.demo.portal.web.importExportFile.FileChangeListener</listener-class>
</listener>
我通過刪除Autowired註釋解決了這個問題,但除了創建一個bean xml外,還有其他任何方法,以便我們可以使用自動裝配對象和石英。在此先感謝 –