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