Spring Boot定时任务的使用方法

网友投稿 173 2023-01-23


Spring Boot定时任务的使用方法

本文介绍在Spring Boot 中如何使用定时任务,使用非常简单,就不做过多说明了。

下面是代码类:

package org.springboot.sample.config;

import org.slf4j.Logger;

import org.slf4j.LoggerFactory;

import org.springframework.context.annotation.Configuration;

import org.springframework.scheduling.annotation.EnableScheduling;

import org.springframework.scheduling.annotation.Scheduled;

/**

* 定时任务配置类

*

* @author 单红宇(365384722)

* @myblog http://blog.csdn.net/catoop/

* @create 2016年3月21日

*/

@Configuration

@EnableScheduling // 启用定时任务

public class SchedulingConfig {

private final Logger logger = LoggerFactory.getLogger(getClass());

@Scheduled(cron = "0/20 * * * * ?") // 每20秒执行一次

public void scheduler() {

logger.info(">>>>>>>>>&ghttp://t;>>> scheduled ... ");

}

}


版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:JAVA中通过自定义注解进行数据验证的方法
下一篇:JDK 1.8 安装配置教程(win7 64bit )
相关文章

 发表评论

暂时没有评论,来抢沙发吧~