• quartz + spring 启动项目时,报错The web application [] appears to have started a thread named.........


      只是想记录自己的错误信息,下次再出现就知道怎么操作,不用再查找资料

    解决办法:

    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>

    虽然不报错了,但是把这个注释掉,也不报错了,不知道程序发什么疯,可能有些原理还不知道

  • 相关阅读:
    python+Appium自动化:BSTestRunner执行测试用例,生成测试报告
    python3基础:介绍几个函数的用法
    python3基础:格式化输出
    python+Appium自动化:框架设计
    python+Appium自动化:PageObject设计模型
    python+Appium自动化:logging配置代码分离
    python+Appium自动化:日志logging模块
    python+Appium自动化:yaml配置capability
    Monkey基本命令
    Monkey介绍
  • 原文地址:https://www.cnblogs.com/Cassie-wang/p/9646864.html
Copyright © 2020-2023  润新知