maven引入所需的jar包:
<dependency> <groupId>org.quartz-scheduler</groupId> <artifactId>quartz</artifactId> <version>2.2.2</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context-support</artifactId> <version>4.2.5.RELEASE</version> </dependency>
spring的配置如下:
<!-- 启动触发器的配置开始 --> <bean id="startQuertz" lazy-init="false" autowire="no" class="org.springframework.scheduling.quartz.SchedulerFactoryBean"> <property name="triggers"> <list> <ref bean="analyzeMonthPageAccessTrigger" /> </list> </property> </bean> <!-- 启动触发器的配置结束 --> <!-- 调度的配置开始 --> <bean id="analyzeMonthPageAccessTrigger" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean"> <property name="jobDetail"> <ref bean="analyzeMonthPageAccessJobDetail" /> </property> <property name="cronExpression"> <!-- 每5秒执行一次,调试用 --> <!-- <value>0/5 * * * * ?</value> --> <!-- 每月的1号凌晨1点执行 --> <value>0 0 1 1 * ? *</value> </property> </bean> <!-- 调度的配置结束 --> <!-- job的配置开始 --> <bean id="analyzeMonthPageAccessJobDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"> <property name="targetObject"> <ref bean="mGPageAccessService"/> </property> <property name="targetMethod"> <value>analyzeMonthPageAccess</value> </property> </bean> <!-- job的配置结束 -->
本文出自 “架构师之路” 博客,请务必保留此出处http://lizhuquan0769.blog.51cto.com/2591147/1763263
原文地址:http://lizhuquan0769.blog.51cto.com/2591147/1763263