Springboot几种任务的整合方法

本文详述了Springboot中异步任务、定时任务和邮件任务的整合方法,包括启动类、Controller层、Service层的配置以及测试结果。对于定时任务,提到了基于注解的不便之处,并预告将探讨Quartz与Springboot结合的解决方案。此外,还简单提及了邮件任务的配置流程。最后,作者提到将在后续分享中深入讨论这些任务在实际项目中的应用。
摘要由CSDN通过智能技术生成

这篇文章主要介绍了Springboot几种任务的整合方法,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下

一 异步任务

启动类
@MapperScan("com.topcheer.*.*.dao")
@SpringBootApplication
@EnableCaching
@EnableRabbit
@EnableAsync
public class Oss6Application {
   
  public static void main(String[] args) {
   
    SpringApplication.run(Oss6Application.class, args);
  }
}
Controller层
/**
 * @author WGR
 * @create 2019/10/12 -- 21:53
 */
@RestController
public class AsynController {
   @Autowired
  AsynService asyncService;@GetMapping("/hello")
  public String hello(){
   
    asyncService.hello();
    return "success";
  }
}
Service层
/**
 * @author WGR
 * @create 2019/10/12 -- 21:52
 */
@Service
public class AsynService {
   //告诉Spring这是一个异步方法
  @Async
  public 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值