1.增加执行类
@Slf4j
@EnableScheduling // 2.开启定时任务
@Component
@ImportResource(value ="classpath:/scheduling-config.xml")
public class WeixinInfoTransferJob{
@Autowired
FusionEAMAPIUtil frutil = new FusionEAMAPIUtil();
static String INFORM_DATE = "4";//周几进行下周维护任务的通知
@Autowired
WeixinMessageService wxService;
protected void execute()
throws JobExecutionException {
log.info("{}:执行定时任务-"+this.getClass().getName()+",开始...",LocalDateTime.now());
Date nowDate = new Date();
SimpleDateFormat myFormatter = new SimpleDateFormat("yyyy-MM-dd");
//通知明天任务
String InfoDate = myFormatter.format(DateUtils.addDays(nowDate,0));
try {
List<WorkOrder> list =frutil.getPreventWkOdrs("PREVENTIVE", "ORA_RELEASED",InfoDate );
if(CollectionUtil.isNotEmpty(list)){
wxService.send("112520,083380","", list.toString());
}
} catch (Exception e) {
log.error(this.getClass().getName()+":获取工单失败:"+e.getMessage());
}
log.info("{}:执行定时任务-"+this.getClass().getName()+",成功...",LocalDateTime.now());
}
}
2.增加sheduling-config.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"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="weixinInfoJob" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject" ref="weixinInfoTransferJob"></property>
<!-- 要执行的方法 -->
<property name="targetMethod" value="execute"></property>
</bean>
<bean id="SchedulerTaskTrigger" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
<property name="jobDetail" ref="weixinInfoJob" />
<property name="cronExpression">
<value>*/10 * * * * ?</value>
</property>
</bean>
<!-- 配置Job类 -->
<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref bean="SchedulerTaskTrigger" />
</list>
</property>
</bean>
</beans>
3.增加pom.xml的maven依赖
<dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz</artifactId>
<version>${quartz.version}</version>
<exclusions>
<exclusion>
<groupId>com.mchange</groupId>
<artifactId>c3p0</artifactId>
</exclusion>
</exclusions>
</dependency>
在<properties>标签增加
<quartz.version>2.3.0</quartz.version>