spingboot @EnableScheduling
springboot让开发更简单!springmvc中启用定时任务还得需要在xml中进行配置启用并且要配置扫描器,但是springboot只需要一个注解就可以。
@EnableScheduling
无需多余的jar依赖,所以pom不贴了
applaction.java
- package com.sbm;
- import org.springframework.boot.SpringApplication;
- import org.springframework.boot.autoconfigure.SpringBootApplication;
- import org.springframework.scheduling.annotation.EnableScheduling;
- @SpringBootApplication
- @EnableScheduling
- public class Application {
- public static void main(String[] args) {
- SpringApplication.run(Application.class, args);
- }
- }
定时任务类AppCoreTask.java
- package com.sbm.scheduling;
- import org.springframework.scheduling.annotation.Scheduled;
- import org.springframework.stereotype.Component;
- import java.util.Date;
- @Component
- public class AppCoreTask {
- @Scheduled(cron = "0 53 15 * * ? ")
- public void tesk() {
- System.out.print("开启定时任务" + new Date());
- }
- }
要求在15:53分打印一句话
关于cron表达式的用法,可以在我的这篇文章里查看:Spring Task 中cron表达式整理记录
运行sb程序
- 016-12-30 15:52:24.653 INFO 4204 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
- 2016-12-30 15:52:24.654 INFO 4204 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
- 2016-12-30 15:52:24.722 INFO 4204 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
- 2016-12-30 15:52:25.183 INFO 4204 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
- 2016-12-30 15:52:25.212 INFO 4204 --- [ main] s.a.ScheduledAnnotationBeanPostProcessor : No TaskScheduler/ScheduledExecutorService bean found for scheduled processing
- 2016-12-30 15:52:25.315 INFO 4204 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http)
- 2016-12-30 15:52:25.326 INFO 4204 --- [ main] com.sbm.Application : Started Application in 7.124 seconds (JVM running for 8.234)
- 开启定时任务Fri Dec 30 15:53:00 CST 2016
spingboot @EnableScheduling的更多相关文章
- vue打包发布在spingboot项目中 vue-router路由的处理
(原) 以下例子springboot后端地址为:localhost:7080/pingandai vue前端地址为:locahost:8080/pingandai/ 1.如果路由模式设置的是histo ...
- @EnableScheduling注解
@EnableScheduling 开启对定时任务的支持 其中Scheduled注解中有以下几个参数: 1.cron是设置定时执行的表达式,如 0 0/5 * * * ?每隔五分钟执行一次 ...
- Spring boot @EnableScheduling 和 @Scheduled 注解使用例子
前言 Spring Boot提供了@EnableScheduling和@Scheduled注解,用于支持定时任务的执行,那么接下来就让我们学习下如何使用吧: 假设我们需要每隔10秒执行一个任务,那么我 ...
- SpringBoot系列——EnableScheduling,对定时器的支持
前言 定时器功能在项目里面往往会用到,比如定时发送邮件.定时释放数据库资源:这里记录一下springboot对定时器的支持的简单实例 cron表达式 开始之前要先介绍一下cron表达式,这里当一下百度 ...
- spingBoot整合mybatis+generator+pageHelper
spingBoot整合mybatis+generator+pageHelper 环境/版本一览: 开发工具:Intellij IDEA 2018.1.4 springboot: 2.0.4.RELEA ...
- spring自带的定时任务功能@EnableScheduling
1 demo package com.test.domi.config; import org.springframework.beans.factory.annotation.Configurabl ...
- Spring注解之 @EnableScheduling计划任务注解
要实现计划任务,首先通过在配置类注解@EnableScheduling来开启对计划任务的支持, 然后在要执行计划任务的方法上注解@Scheduled,声明这是一个计划任务 示例:计划任务执行类 在这个 ...
- SpingBoot的认识和基本使用
认识SpingBoot Spring Boot是由Pivotal团队提供的全新框架,其设计目的是用来简化Spring应用的初始搭建以及开发过程. -使用springboot以后,搭建一个spring应 ...
- spingboot集成jpa(一)
springboot + jpa 练习 spingboot集成jpa(一):最基本的环境搭建 spingboot集成jpa(二):使用单元测试 1. pom.xml中添加依赖 <!-- jdbc ...
随机推荐
- python 切片知识大全
切片 无论是在工作中,还是面试的过程性,总会有那么几个关于对某一个集合进行切片,得到我们想要的部分.可见这部分虽然简单但还是很重要的,正确运用可以使你更有效的解决一些复杂的问题.下面我们就正式进行有关 ...
- [转]【ROLLUP】Oracle分组函数之ROLLUP魅力
原创:http://blog.itpub.net/519536/viewspace-610995 本文通过演示给出Oracle ROLLUP分组函数的用法,体验一下Oracle在统计查询领域中的函数魅 ...
- 《算法》第三章部分程序 part 5
▶ 书中第三章部分程序,加上自己补充的代码,包含公共符号表.集合类型 ● 公共符号表,用于普通查找表的基本类 package package01; import java.util.NoSuchEle ...
- div的全屏与退出全屏
div的全屏与退出全屏 作用:将div全屏与退出全屏,一般播放器使用较多. html按钮: <button onclick="showFull();"> 全屏 < ...
- [记录] CSS 左边元素定长,右边元素获得剩余长度
情景:左边元素定长,右边元素获得剩余长度 1. 左边设置浮动,右边元素宽度auto,可以不设置,默认auto,然后设置margin-left:左边元素宽度 <ul class="ent ...
- linux-2.6.22.6 内核源代码包的文件目录介绍
下载一个linux-2.6.22.6.tar并解压 再其解压的文件中加入下面的bat脚本 生成当前文件的目录树脚本如下: @rem 此BAT文件名一定不能是"tree.bat",否 ...
- Linux中的Wheel组的作用
原文:http://www.360doc.com/content/11/0505/10/4644186_114496525.shtml Linux中的Wheel组的作用(用自己的话翻译的) (原文) ...
- PHP中Notice: unserialize(): Error at offset of bytes in on line 的解决方法
使用unserialize函数将数据储存到数据库的时候遇到了这个报错,后来发现是将gb2312转换成utf-8格式之后,每个中文的字节数从2个增加到3个之后导致了反序列化的时候判断字符长度出现了问题, ...
- 列表(list) 的 基本操作
举例说明:names = ["zhangyang", "guyun", 'xiangpeng', ['alex','jack'], "xuliangc ...
- otter使用
参考网址:https://github.com/alibaba/otter/wiki/QuickStart 参考网址: https://www.aliyun.com/jiaocheng/1127326 ...