博客
关于我
SpringBoot实现异步方法
阅读量:104 次
发布时间: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/

你可能感兴趣的文章
on_member_join 和删除不起作用.如何让它发挥作用?
查看>>
oobbs开发手记
查看>>
OOM怎么办,教你生成dump文件以及查看(IT枫斗者)
查看>>
OOP
查看>>
OOP之单例模式
查看>>
OOP向AOP思想的延伸
查看>>
OO第一次blog
查看>>
OO第四单元总结
查看>>
OO第四次博客作业
查看>>
OO面向对象编程:第三单元总结
查看>>
Opacity多浏览器透明度兼容处理
查看>>
OPC在工控上位机中的应用
查看>>
VSCode在终端中使用yarn命令
查看>>
OPEN CASCADE Curve Continuity
查看>>
Open Graph Protocol(开放内容协议)
查看>>
Open vSwitch实验常用命令
查看>>
Open WebUI 忘了登入密码怎么办?
查看>>
open***负载均衡高可用多种方案实战讲解02(老男孩主讲)
查看>>
Open-E DSS V7 应用系列之五 构建软件NAS
查看>>
Open-Sora代码详细解读(1):解读DiT结构
查看>>