只是想记录自己的错误信息,下次再出现就知道怎么操作,不用再查找资料
解决办法:
package com.wqq.quartz_test.schedule; import javax.servlet.ServletContextEvent; import javax.servlet.ServletContextListener; import org.springframework.web.context.WebApplicationContext; /** * @author wangqq * @version 创建时间:2018年9月14日 上午9:49:29 * 类说明 */ public class QuartzContextListener implements ServletContextListener { @Override public void contextInitialized(ServletContextEvent sce) { // TODO Auto-generated method stub } @Override public void contextDestroyed(ServletContextEvent arg0) { // TODO Auto-generated method stub WebApplicationContext webApplicationContext = (WebApplicationContext) arg0 .getServletContext() .getAttribute( WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE); org.quartz.impl.StdScheduler startQuertz = (org.quartz.impl.StdScheduler) webApplicationContext .getBean("startQuertz"); if(startQuertz != null) { startQuertz.shutdown(); } try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } } }
其中
"startQuertz" 是在spring-quartz.xml中
<bean id="startQuartz" lazy-init="false" autowire="no" class="org.springframework.scheduling.quartz.SchedulerFactoryBean"> <property name="triggers"> <list> <ref bean="jobTriggerA"/> <ref bean="jobTriggerB"/> </list> </property> <property name="quartzProperties"> <props> <prop key="org.quartz.scheduler.instanceName">buy_it_now</prop> <prop key="org.quartz.threadPool.threadCount">2</prop> <prop key="org.quartz.plugin.shutdownhook.class">org.quartz.plugins.management.ShutdownHookPlugin</prop> <prop key="org.quartz.plugin.shutdownhook.cleanShutdown">true</prop> <prop key="org.quartz.threadPool.threadsInheritContextClassLoaderOfInitializingThread">true</prop> </props> </property> <property name="configLocation" value="classpath:quartz/quartz.properties"></property> <property name="applicationContextSchedulerContextKey" value="applicationContext" /> </bean>
然后在web.xml中配置
<listener> <listener-class>com.wqq.quartz_test.schedule.QuartzContextListener</listener-class> </listener>
虽然不报错了,但是把这个注释掉,也不报错了,不知道程序发什么疯,可能有些原理还不知道