详细的错误信息如下:

 -- ::13.366 [DefaultQuartzScheduler_Worker-] ERROR org.quartz.core.JobRunShell: - Job group1.job1 threw an unhandled Exception:
 java.lang.NullPointerException
     at com.starunion.java.service.timer.JobEndConference.execute(JobEndConference.java:) ~[bin/:?]
     at org.quartz.core.JobRunShell.run(JobRunShell.java:) [quartz-2.2..jar:?]
     at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:) [quartz-2.2..jar:?]
 -- ::13.374 [DefaultQuartzScheduler_Worker-] ERROR org.quartz.core.ErrorLogger: - Job (group1.job1 threw an exception.
 org.quartz.SchedulerException: Job threw an unhandled exception.
     at org.quartz.core.JobRunShell.run(JobRunShell.java:) [quartz-2.2..jar:?]
     at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:) [quartz-2.2..jar:?]
 Caused by: java.lang.NullPointerException
     at com.starunion.java.service.timer.JobEndConference.execute(JobEndConference.java:) ~[bin/:?]
     at org.quartz.core.JobRunShell.run(JobRunShell.java:) ~[quartz-2.2..jar:?]

说说我的解决过程:

一、原因很明显:调用了null对象。

但是这是因为我调用了service的方法

 我用的方法

静态工具类

创建工具类SpringContextJobUtil,实现ApplicationContextAware接口,此工具类会在spring容器启动后,自动加载,使用其提供的getBean方法获取想要的bean即可

@Component
public class SpringContextJobUtil implements ApplicationContextAware  {

    private static ApplicationContext context;

    @Override
    @SuppressWarnings("static-access" )
    public void setApplicationContext(ApplicationContext contex)
            throws BeansException {
        // TODO Auto-generated method stub
        this.context = contex;
    }
    public static Object getBean(String beanName){
        return context.getBean(beanName);
    }

    public static String getMessage(String key){
        return context.getMessage(key, null, Locale.getDefault());
    }
}

在job内直接调用静态方法

testSuitService = (TestSuitService) SpringContextJobUtil.getBean("testSuitService");

参考的网站:

https://www.bbsmax.com/A/obzbYvq6dE/

https://www.jianshu.com/p/aff9199b4416

 

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐