首页 > 其他分享 >springboot整合springTask

springboot整合springTask

时间:2023-05-06 23:15:06浏览次数:31  
标签:springboot springTask public 整合 new 定时 class

一、启动类开启task注解

//springTask定时任务开启
@EnableScheduling
@SpringBootApplication
@MapperScan("com.zhenghe.mapper")
public class ZhengheApplication {
    public static void main(String[] args) {

        SpringApplication.run(ZhengheApplication.class,args);
    }
}

二、编写实际要执行的定时任务

@Component
public class TestTask {

    @Scheduled(cron = "0/5 * * * * *")
    private void test(){
        //这里是要写实际执行的定时任务业务
        System.out.println("定时任务开启:"+new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
    }

}

三、启动测试

标签:springboot,springTask,public,整合,new,定时,class
From: https://www.cnblogs.com/wlfs000000/p/17378655.html

相关文章

  • springboot整合security+jwt
    一、引入相关依赖<!--springsecurity依赖--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-security</artifactId></dependency><!--jwt依赖--><dependency>......
  • SpringBoot集成RocketMQ
    添加pom.xml依赖<dependency><groupId>org.apache.rocketmq</groupId><artifactId>rocketmq-spring-boot-starter</artifactId><version>2.2.3</version></dependency>创建消息消费者@Component@Slf4jpublicclass......
  • spring和hibernate配置文件整合
    为了操作方便,我们经常在spring整合hibernate的WEB项目中省去了用hibernate.cfg.xml的麻烦,将hibernate的信息直接配置在Spring配置文件中下面的都是针对Spring整合Hibernate(注解方式的hibernate)来说的hibernate.cfg.xml和applicationContext.xml原始配置......
  • 【SpringBoot】【六】 刷新上下文
    1 前言上节我们看了上下文的创建和准备,那么我们这节就来看看刷新上下文。2 刷新上下文首先就是我们的run方法,执行刷新上下文  refreshContext(context)://###run方法refreshContext(context);//###SpringApplicationprivatevoidrefreshContext(ConfigurableApp......
  • 【SpringBoot】【五】 创建、准备上下文
    1 前言上节我们看了下环境准备,那么接下来我们就要看重头了,就是创建和准备上下文了。//创建上下文context=createApplicationContext();//加载异常解析报告类exceptionReporters=getSpringFactoriesInstances(SpringBootExceptionReporter.class,newClass[......
  • SpringBoot 操作 MongoDB 新增和查询
    MongoDBJAVA新增+查询上接SpringBoot整合MongoDB,记一下MongoDB的CRUD方法。Create新增使用MongoRepository方式的新增非常简单,之前的整合中已经尝试过,这里再总结一下:首先需要有对应的实体类对象:@Data@AllArgsConstructor@NoArgsConstructor@ToStringpublicc......
  • 聊聊关于,SpringBoot写后端接口
    前言:一个后端接口大致分为四个部分组成:接口地址(url)、接口请求方式(get、post等)、请求数据(request)、响应数据(response)。如何构建这几个部分每个公司要求都不同,没有什么“一定是最好的”标准,但一个优秀的后端接口和一个糟糕的后端接口对比起来差异还是蛮大的,其中最重要的关键点就是......
  • SpringBoot 自动扫描第三方包及spring.factories失效的问题
    为什么会找不到Spring依赖注入就是要让spring找到要注入的类并且识别到了@Component、@Service等注解。1.当在开发的第三方包里写明了@Component、@Service等等2.引入了包,不论第三方库的引入,还是本地jar。总之是要引入到工程的这时候还加入不到IOC容器,那就说明Spri......
  • Springboot 系列 (30) - Springboot+HBase 大数据存储(八)| Springboot Client/Server
    Kerberos(SecureNetworkAuthenticationSystem,网络安全认证系统),是一种网络认证协议,其设计目标是通过密钥系统为Client/Server提供强大的认证服务。该认证过程的实现不依赖于主机操作系统的认证,无需基于的信任,不要求网络上所有主机的物理安全,并假定网络上传送的数据包可以被......
  • 【Spring篇】Spring整合
    目录一、Spring整合1.Spring整合Mybatis思路分析1.环境准备2.整合思路分析2.Spring整合Mybatis3.Spring整合Junit1.环境准备2.整合Junit步骤 一、Spring整合1.Spring整合Mybatis思路分析1.环境准备在准备环境的过程中,我们也来回顾下Mybatis开发的相关内容:步骤1:准备数据库表......