首先配置一个定时任务,0 35 13 * * *代表每天的下午13:25分到class="com.qianmo.qmyj.cache.impl.AutoTransImpl"执行定时任务
1 <!--开启任务注解扫描-->
2 <task:annotation-driven/>
3 <bean id="autoTransTask" class="com.qianmo.qmyj.cache.impl.AutoTransImpl"/>
4 <task:scheduled-tasks>
5 <!--此计划任务用于用户不给好评,从工人点击完工(7日后)自动 5星好评 并且 转账-->
6 <task:scheduled ref="autoTransTask" method="executeAutoTrans" cron="0 35 13 * * *"/>
7 </task:scheduled-tasks>
8
9 <!-- 启用spring事务处理(同一个service中有一条数据库操作失败,之前的方法全部回滚) -->
10 <tx:annotation-driven transaction-manager="transactionManager"/>
/*
* Package com.qianmo.qmyj.cache
* FileName: AutoTransImpl
* Date: 2017/5/7 2:44
*/
package com.qianmo.qmyj.cache.impl;import javax.annotation.Resource;
import java.util.List;
/**
* FileName: AutoTransImpl
* Author: anpei
* Date: 2017/5/7
* Description: 自动转账以及好评(7日)
*/
@Component("autoTrans")
public class AutoTransImpl implements AutoTrans {
private Logger logger = LoggerFactory.getLogger(getClass());
@Resource
private OrderInfoDao orderInfoDao;
@Override
@Transactional(propagation = Propagation.REQUIRES_NEW)
public int executeAutoTrans() {
int count = 1;
system.out.print("定时任务开始");
return count;
}
}