使用Quartz和Spring的NullPointerException

ste*_*own 2 java spring tomcat quartz-scheduler apache-commons-logging

我正在使用Spring Quartz集成,每次我尝试关闭Tomcat时,Quartz进程都无法关闭.这是堆栈跟踪:

Exception in thread "org.springframework.scheduling.quartz.SchedulerFactoryBean#0_QuartzSchedulerThread" 
        java.lang.NullPointerException
    at org.apache.commons.logging.LogFactory.getCachedFactory(LogFactory.java:979)
    at org.apache.commons.logging.LogFactory.getFactory(LogFactory.java:435)
    at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:685)
    at org.quartz.core.QuartzSchedulerThread.getLog(QuartzSchedulerThread.java:475)
    at org.quartz.core.QuartzSchedulerThread.run(QuartzSchedulerThread.java:404)
Run Code Online (Sandbox Code Playgroud)

以前有人看过这个吗?

mat*_*t b 7

如果查看SchedulerFactoryBean,它有一个名为的属性waitForJobsToCompleteOnShutdown.当Spring ApplicationContext收到关闭请求时,它会告诉Quartz Scheduler关闭,有条件地告诉它在关闭之前等待所有作业完成.

但是,如果通知Tomcat上下文被处理,Spring只能处理关闭请求(并告诉Quartz)关闭.你是如何在Tomcat中使用Spring的?你有ServletContextListener注册的电话applicationContext.destroy()吗?

实际的NPE可能是由Tomcat 在关闭时设置static应用程序运行的classLoader中的所有引用引起的null.这样做有助于防止在Tomcat的回收/重启期间发生任何内存泄漏.但是,如果您的Tomcat容器中存在仍在运行的线程(因为它们没有正确关闭,例如您的Quartz线程),那么当该线程中的代码(例如您的代码中的代码)时您将看到错误尝试访问它的记录器的Quartz线程(可能保留为static)尝试访问已被删除的任何静态引用.