• spring中配置quartz


     <!-- Scheduler 总入口 -->
     <bean id="myTest" class="com.zte.adc.search.web.SearchStateTask"
      autowire="byName" lazy-init="true">
     </bean>
     <bean id="jobDetail"
      class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
      <property name="targetObject" ref="myTest" />
      <!-- 调用 com.zte.adc.search.web.SearchStateTask 类下的 execute方法-->
      <property name="targetMethod" value="execute" />
     </bean>

     <!-- 触发器 -->
     <bean id="cronTrigger"
      class="org.springframework.scheduling.quartz.CronTriggerBean">
      <property name="jobDetail">
       <ref bean="jobDetail" />
      </property>

      <property name="cronExpression">
       <!-- 秒 分 时 每月几号 月 星期 年   每60秒执行一次-->
       <value>0/60 * * * * ?</value>
      </property>
     </bean>

     <bean id="scheduler"
      class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
      <property name="triggers">
       <list>
        <ref local="cronTrigger" />
       </list>
      </property>
     </bean>

    创建 SearchStateListener

    public class SearchStateListener extends HttpServlet implements
      ServletContextListener {

    public void contextInitialized(ServletContextEvent arg0) {
       BeanFactory factory = new ClassPathXmlApplicationContext(
         "applicationContext.xml");
      }
     }

    }

    web.xml配置

     <listener>
      <listener-class>
       com.zte.adc.search.web.SearchStateListener
      </listener-class>
     </listener>

    在服务器启动时就会自动启动 quartz

  • 相关阅读:
    第十八周个人作业
    十六周个人作业
    个人作业
    第十四周总结
    第十三周周末总结
    排球计分程序说明书
    我和计算机
    排球比赛记分员
    逻辑思维怎样成为一个高手
    用户故事排球教练助手
  • 原文地址:https://www.cnblogs.com/liaomin416100569/p/9331857.html
Copyright © 2020-2023  润新知