错误org.quartz.core.JobRunShell - 作业group1.JobReport抛出未处理的异常

时间:2016-04-19 01:50:28

标签: quartz-scheduler

使用QUARTZ调度程序生成报告时存在一个奇怪的问题

我可以生成一份报告!没问题。

方法(reportsBean)正常工作,但在通过quartz

时出现问题

有什么想法吗?我不知道该怎么办:/

  

13449 [MyScheduler_Worker-1] ERROR org.quartz.core.JobRunShell - 工作   group1.JobReport抛出了未处理的异常:   java.lang.NullPointerException at   com.changes.bean.ReportsBean.createPdfCriticalChanges(ReportsBean.java:104)     在com.changes.quartz.JobReport.execute(JobReport.java:36)at   org.quartz.core.JobRunShell.run(JobRunShell.java:202)at at   org.quartz.simpl.SimpleThreadPool $ WorkerThread.run(SimpleThreadPool.java:573)   13452 [MyScheduler_Worker-1] ERROR org.quartz.core.ErrorLogger - 工作   (group1.JobReport引发了一个异常.org.quartz.SchedulerException:   约克投掷了一个未经处理的例外。 [见嵌套异常:   java.lang.NullPointerException] at   org.quartz.core.JobRunShell.run(JobRunShell.java:213)at at   org.quartz.simpl.SimpleThreadPool $ WorkerThread.run(SimpleThreadPool.java:573)   引起:java.lang.NullPointerException at   com.changes.bean.ReportsBean.createPdfCriticalChanges(ReportsBean.java:104)     在com.changes.quartz.JobReport.execute(JobReport.java:36)at   org.quartz.core.JobRunShell.run(JobRunShell.java:202)

reportsbean

public class JobReport implements Job {


    public void execute(JobExecutionContext context) throws JobExecutionException {


        //BasicConfigurator.configure();
        try {
            ReportsBean reportsBean = new ReportsBean();
            reportsBean.createPdfCriticalChanges();
            SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy – hh:mm:ss");
            System.out.println("Rodou: " + dateFormat.format( new Date() ));
        } catch (JRException | SQLException e) {
            e.printStackTrace();
        }

    }

}

quartz.properties

org.quartz.scheduler.instanceName = MyScheduler
org.quartz.threadPool.threadCount = 3
org.quartz.jobStore.class = org.quartz.simpl.RAMJobStore
org.quartz.plugin.jobInitializer.class =org.quartz.plugins.xml.XMLSchedulingDataProcessorPlugin
org.quartz.plugin.jobInitializer.fileNames = com/changes/quartz/quartz-config.xml
org.quartz.plugin.jobInitializer.failOnFileNotFound = true

的web.xml

<!-- Inicio Quartz -->
<servlet>
    <servlet-name>QuartzServlet</servlet-name>
    <servlet-class>com.changes.quartz.servlet.QuartzServlet</servlet-class>
</servlet>
<servlet>
    <servlet-name>QuartzInitializer</servlet-name>
    <servlet-class>org.quartz.ee.servlet.QuartzInitializerServlet</servlet-class>
    <init-param>
        <param-name>config-file</param-name>
        <param-value>quartz.properties</param-value>
    </init-param>
    <init-param>
        <param-name>shutdown-on-unload</param-name>
        <param-value>true</param-value>
    </init-param>
    <init-param>
        <param-name>start-scheduler-on-load</param-name>
        <param-value>true</param-value>
    </init-param>
    <load-on-startup>2</load-on-startup>
</servlet>
<!-- Fim Quartz -->

5 个答案:

答案 0 :(得分:0)

问题是您在ReportsBean中有一个NullPointerException。

由于Quartz执行方法的签名是

public void execute(JobExecutionContext context) throws JobExecutionException

Quartz只能处理将在此方法中抛出的JobExecutionException。但在你的情况下,它会出现意外的NullPointerException。

要解决此问题,您应该删除NullPointer的原因。 从上面的源代码我无法弄清楚这个异常的原因,因为它发生在您的ReportsBean中。

当然,您的方法ReportsBean.createPdfCriticalChanges试图访问未初始化的成员。

答案 1 :(得分:0)

在第104行: String report FacesContext.getCurrentInstance().getExternalContext().getRealPath("/web/reports/criticalcr.jrxml");

请记住:它是用石英制作的。

ReportsBean

public void createPdfCriticalChanges() throws JRException,SQLException {
            System.out.println("generating report...");

            String report = FacesContext.getCurrentInstance().getExternalContext().getRealPath("/web/reports/criticalcr.jrxml");
            JasperReport pathjrxml = JasperCompileManager.compileReport(report);
            //JasperReport pathjrxml = JasperCompileManager.compileReport("web/reports/criticalcr.jrxml"); //Funciona com o inicia Agenda em XML "web/reports/changetracker_criticalcr.jrxml"
            JasperPrint printReport = JasperFillManager.fillReport(pathjrxml, null, conn.getConn());
            JasperExportManager.exportReportToPdfFile(printReport, "/web/reports/changetracker_criticalcr.pdf"); //Funciona com o inicia Agenda em XML "web/reports/criticalcr.pdf"
            System.out.println("report generated!");
    }

答案 2 :(得分:0)

使用@postController和@override方法init不会抛出JobExecutionExceptionnb

答案 3 :(得分:0)

我遇到了同样的问题,我通过将大于当前时间的时间放入存储next_fire_time的表中来解决。然后重新启动服务器。

答案 4 :(得分:0)

ReportsBean 无法在该位置创建对象。如果是 Spring 应用程序,请使用@Autowired批注来解决此问题:

@Autowired
ReportsBean reportsBean;

然后使用呼叫reportsBean.yourMethod();