发表于: 2018-06-10 23:06:21
2 869
今天完成的任务:
继续昨天的spring定时任务,昨天看了quartz的实现方法,今天看一下springtask,可以把它比作一个轻量级的quartz,支持注解和配置文件两种形式。
1配置文件
1.1编写作业类
import org.springframework.stereotype.Service;
@Service
public class TaskJob {
public void job1() {
System.out.println(“任务进行中。。。”);
}
}
1.2在spring配置文件头中添加命名空间
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd">
1.3spring配置文件中设置具体的任务
<task:scheduled-tasks>
<task:scheduled ref="taskJob" method="job1" cron="0 * * * * ?"/>
</task:scheduled-tasks>
<context:component-scan base-package=" com.gy.mytask " />
ref参数指定的即任务类,method指定的即需要运行的方法,cron及cronExpression表达式
2.使用注解形式
使用@Scheduled注解:
cron:指定cron表达式
fixedDelay:官方文档解释:An interval-based trigger where the interval is measured from the completion time of the previous task. The time unit value is measured in milliseconds.即表示从上一个任务完成开始到下一个任务开始的间隔,单位是毫秒。
fixedRate:官方文档解释:An interval-based trigger where the interval is measured from the start time of the previous task. The time unit value is measured in milliseconds.即从上一个任务开始到下一个任务开始的间隔,单位是毫秒。
今天弄wiki上的文档弄了好久,好久不弄格式问题,明天应该可以弄完wiki上的接口文档。
今天的收获:
又看了下网盘里面老大讲的和培宇讲的视频,对公司自动生成代码又了解了一些。
今天遇到的问题:
service是怎么分的?controller是分为前台和后台,那service怎么分。。
明天的计划:
后端方案
评论