quartz是一个非常强大的任务调度器。我们可能使用它来管理我们的项目,常见的是做业绩统计等等。当然它的功能远不止这些。我们在这里不介绍quartz的原理,下面讲讲如何在springboot中使用quartz。
废话不多说,直接上源码:
首先看一下我们需要利用quartz执行的类和方法
productSellDailyService接口:
/** * 统计日销量的业务逻辑层 */ public interface ProductSellDailyService { //每日定时对店铺的销量进行统计 void dailyCalculate(); }
对应的实现类:
import net.cqwu.collegeo2o.dao.ProductSellDailyMapper; import net.cqwu.collegeo2o.service.ProductSellDailyService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @Service public class ProductSellDailyServiceImpl implements ProductSellDailyService { private static final Logger log = LoggerFactory.getLogger(ProductSellDailyServiceImpl.class);