zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    IDEA 必要配置
    人工智能能力提升指导总结
    lerna管理前端packages的最佳实践
    【和60】软件即服务的三重境界
    项目章程
    阅读计划
    使用PHP处理文本小技巧
    PHP性能分析
    Ubuntu安装nodejs和yarn
    挖矿病毒
  • 原文地址:https://www.cnblogs.com/liaomin416100569/p/9331857.html
Copyright © 2011-2022 走看看