springboot集成task

本例场景:
    springboot集成task
    本例demo源码: https://github.com/zhangbeizhen/springboot-task
1.在SpringbootTaskApplication使用@EnableScheduling注解启动定时功能

@EnableScheduling /**开启基于注解的定时任务*/
@SpringBootApplication
public class SpringbootTaskApplication {
  public static void main(String[] args) {
  	SpringApplication.run(SpringbootTaskApplication.class, args);
  }
}

2.在ScheduledService使用@Scheduled注定配置定时任务

@Service
public class ScheduledService {
  private static final Logger logger = LoggerFactory.getLogger(ScheduledService.class);
  @Scheduled(cron = "0/5 * * * * ?")  //每5秒执行一次
  public void doWork(){
    logger.info("测试开始......");
    logger.info("正在执行......");
    logger.info("测试结束......");
  }
}

3.测试截图
    
以上,TKS.

SpringBoot中常用的技术集成包括@ConfigurationProperties、集成Mybatis-Plus、Web组件的使用、集成Redis、集成RabbitMQ、LogBack日志、Swegger2集成、阿里云OSS对象存储、HttpClient和Task定时任务等。 在配置类中,可以使用@Configuration注解声明一个配置类,并通过@Bean注解声明交换机、队列和交换机队列绑定的方法。例如,在MQConfig配置类中,声明了一个名为springbootExchange的交换机、一个名为springbootQueue的队列,并通过@Bean注解将队列绑定到交换机上。 在启动类中,可以使用@SpringBootAppliation注解标记一个类为SpringBoot的启动类,并通过@ServletComponentScan注解自动扫描WebServlet注解。例如,在GpDblSpringbootServletApplication启动类中,使用了@SpringBootAppliation注解,并通过@ServletComponentScan注解自动扫描WebServlet注解。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [SpringBoot常用技术集成](https://blog.csdn.net/weixin_54158370/article/details/125203662)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *2* [SpringBoot 集成](https://blog.csdn.net/weixin_45676630/article/details/109279977)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值