配置QuartzsSpring.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd
">
<!-- 该配置为预留,现阶段并没有过真正使用 -->
<!-- 自动扫描com.synchro.platform.quartz下的所有类,使其解释为定时任务类 -->
<context:component-scan base-package="com.webcarrier.iframework.quartz" />
<bean id="syncOrderDetail"
class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject" ref="orderQuartz" />
<property name="targetMethod" value="syncOrderStatQuartz" />
<!-- 禁止并发执行 -->
<property name="concurrent" value="false" />
</bean>
<bean id="syncOrderCronTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail" ref="syncOrderDetail" />
<!-- 每隔1分钟触发一次 value="0 0/1 * * * ?"-->
<property name="cronExpression" value="0/12 * * * * ? *" />
</bean>
<bean id="schedulerFactory"
class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref bean="syncOrderCronTrigger" />
</list>
</property>
</bean>
</beans>
实现类
package com.webcarrier.iframework.quartz;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/*import com.imengrui.vims.Interface.service.OrderOpsService;
import com.imengrui.vims.util.PropertiesUtil;*/
@Component(value = "orderQuartz")
public class OrderQuartz {
/*@Autowired
private OrderOpsService orderOpsService;*/
private final Logger logger = Logger.getLogger(OrderQuartz.class);
public void syncOrderStatQuartz() {
/* 是否进行定时任务
String superIs = PropertiesUtil.getValue("super.is");
if (!"yes".equals(superIs))
return;*/
SimpleDateFormat sm=new SimpleDateFormat("yyyyMMddHHmmssss");
String format = sm.format(new Date());
System.out.println(format);
logger.info("OrderQuartz------start");
try {
//orderOpsService.batchSyncOrderStat();
System.out.println("ok");
} catch (Exception e) {
e.printStackTrace();
logger.info("OrderQuartz------error");
}
logger.info("OrderQuartz------end");
}
}
对cron时间的编写调试