博客
关于我
SpringBoot实现异步方法
阅读量:105 次
发布时间:2019-02-25

本文共 1527 字,大约阅读时间需要 5 分钟。

Spring Boot ????????

1. ????Spring Boot Web??

??????????????Spring Initializer??????Spring Boot??????Web Starter????????????????????spring-boot-starter-web???pom.xml?????Spring Boot??????????????????

2. ????????

?Spring Boot??????????????@EnableAsync??????????????????????????????????????????????

@EnableAsync@SpringBootApplicationpublic class Springboot12TaskApplication {    public static void main(String[] args) {        SpringApplication.run(Springboot12TaskApplication.class, args);    }}

?????????????????????????????????Service??

3. ??????Service?

??@Service????????????@Async????????????????????

@Servicepublic class AsyncService {    @Async    public void hello() {        try {            Thread.sleep(3000);        } catch (InterruptedException e) {            e.printStackTrace();        }        System.out.println("?????...");    }}

??????Spring Boot??????????????????????????????????????????????????????

4. ??????Controller?

????????AsyncController???@RestController?????AsyncService???@GetMapping???????????????

@RestControllerpublic class AsyncController {    @Resource    AsyncService asyncService;    @GetMapping("/hello")    public String hello() {        asyncService.hello();        return "success";    }}

?????????Service????HTTP???????????????????????

5. ????

????Spring Boot??????????http://localhost:8080/hello?????Postman?curl?????????

???????????????3????????????????????????????????????

6. ??

??????????????????Spring Boot?????Web??????????????????????????????????????????????????????????????????

转载地址:http://jwz.baihongyu.com/

你可能感兴趣的文章
Quartz学习总结(2)——定时任务框架Quartz详解
查看>>
pm2 start命令中的json格式详解
查看>>
pm2启动报错
查看>>
pm2通过配置文件部署nodejs代码到服务器
查看>>
Unknown character set: 'utf8mb4'
查看>>
PML调用PDMS内核命令研究
查看>>
PMM安装-第一篇
查看>>
PMP知识要点(第九章)
查看>>
PNETLab 镜像包官方下载太慢?不急,最新版本PNET_4.2.10分享!
查看>>
pnpm : 无法加载文件...
查看>>
pnpm 如何安装指定版本
查看>>
pnpm的设计与npm的对比
查看>>
PO VO DTO BO区别及用法
查看>>
pocoserver无限重启_Poco::TCPServer框架解析
查看>>
POCO库中文编程参考指南(4)Poco::Net::IPAddress
查看>>
Quartz基本使用(二)
查看>>
POC项目安装与使用指南
查看>>
Podman核心技术详解
查看>>
pods 终端安装 第三方框架的一些命令
查看>>
Podzielno
查看>>