博客
关于我
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/

你可能感兴趣的文章
Objective-C实现两个日期之间的天数(附完整源码)
查看>>
Objective-C实现两个栈实现队列算法(附完整源码)
查看>>
Objective-C实现两个队列实现栈算法(附完整源码)
查看>>
Objective-C实现两数之和问题(附完整源码)
查看>>
Objective-C实现中介者模式(附完整源码)
查看>>
Objective-C实现中值滤波(附完整源码)
查看>>
Objective-C实现中国剩余定理(附完整源码)
查看>>
Objective-C实现中国剩余定理(附完整源码)
查看>>
Objective-C实现中文模糊查询(附完整源码)
查看>>
Objective-C实现串口通讯(附完整源码)
查看>>
Objective-C实现串逐位和(附完整源码)
查看>>
Objective-C实现串链式存储简单匹配(附完整源码)
查看>>
Objective-C实现主存储器空间的分配和回收(附完整源码)
查看>>
Objective-C实现乘方运算---m的n次方(附完整源码)
查看>>
Objective-C实现乘法持续性multiplicative persistence算法(附完整源码)
查看>>
Objective-C实现二分查找最接近的数值m(附完整源码)
查看>>
Objective-C实现二分查找最接近的数值m(附完整源码)
查看>>
Objective-C实现二叉搜索树算法(附完整源码)
查看>>
Objective-C实现二叉树层序遍历(附完整源码)
查看>>
Objective-C实现二叉树遍历算法(附完整源码)
查看>>