<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" 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-4.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.0.xsd"> <!-- 定义任务bean --> <bean name="paymentOrderJobDetail" class="org.springframework.scheduling.quartz.JobDetailFactoryBean"> <!-- 指定具体的job类 --> <property name="jobClass" value="com.jt.order.job.PaymentOrderJob" /> <!-- 指定job的名称 --> <property name="name" value="paymentOrder" /> <!-- 指定job的分组 --> <property name="group" value="Order" /> <!-- 必须设置为true,如果为false,当没有活动的触发器与之关联时会在调度器中删除该任务 --> <property name="durability" value="true"/> <!-- 指定spring容器的key,如果不设定在job中的jobmap中是获取不到spring容器的 --> <property name="applicationContextJobDataKey" value="applicationContext"/> </bean> <!-- 定义触发器 --> <bean id="cronTrigger" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean"> <property name="jobDetail" ref="paymentOrderJobDetail" /> <!-- 每一分钟执行一次 --> <property name="cronExpression" value="0 0/1 * * * ?" /> </bean> <!-- 定义调度器 --> <bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean"> <property name="triggers"> <list> <ref bean="cronTrigger" /> </list> </property> </bean> </beans>
XML万用转义字符
<![CDATA[]]
java类
public class PaymentOrderJob extends QuartzJobBean{ /** * 1、从上下文中获取spring容器 * 2、从spring容器中获取 orderMapper对象 * 3、执行mapper操作将超时订单状态设置为6:已取消(未付款订单,超时取消) */ @Override protected void executeInternal(JobExecutionContext context) throws JobExecutionException { //获取spring容器 ApplicationContext ac = (ApplicationContext) context.getJobDetail().getJobDataMap().get("applicationContext"); //获取mapper对象 OrderMapper orderMapper = ac.getBean(OrderMapper.class); //设置超时订单状态 Date agoDate = new DateTime().minusDays(2).toDate(); System.out.println(agoDate); orderMapper.updateStatus(agoDate); }
public class PaymentOrderJob extends QuartzJobBean{/** * 1、从上下文中获取spring容器 * 2、从spring容器中获取 orderMapper对象 * 3、执行mapper操作将超时订单状态设置为6:已取消(未付款订单,超时取消) */@Overrideprotected void executeInternal(JobExecutionContext context) throws JobExecutionException {//获取spring容器ApplicationContext ac = (ApplicationContext) context.getJobDetail().getJobDataMap().get("applicationContext");//获取mapper对象OrderMapper orderMapper = ac.getBean(OrderMapper.class);//设置超时订单状态Date agoDate = new DateTime().minusDays(2).toDate();System.out.println(agoDate);orderMapper.updateStatus(agoDate);}