博客
关于我
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实现lamberts ellipsoidal distance朗伯椭球距离算法(附完整源码)
查看>>
Objective-C实现largest AdjacentNumber最大相邻数算法 (附完整源码)
查看>>
Objective-C实现largest subarray sum最大子数组和算法(附完整源码)
查看>>
Objective-C实现largestPrime最大素数的算法 (附完整源码)
查看>>
Objective-C实现lazy segment tree惰性段树算法(附完整源码)
查看>>
Objective-C实现LBP特征提取(附完整源码)
查看>>
Objective-C实现LDPC码(附完整源码)
查看>>
Objective-C实现least common multiple最小公倍数算法(附完整源码)
查看>>
Objective-C实现Lempel-Ziv压缩算法(附完整源码)
查看>>
Objective-C实现Length conversion长度转换算法(附完整源码)
查看>>
Objective-C实现Levenshtein 距离算法(附完整源码)
查看>>
Objective-C实现levenshteinDistance字符串编辑距离算法(附完整源码)
查看>>
Objective-C实现lfu cache缓存算法(附完整源码)
查看>>
Objective-C实现LFU缓存算法(附完整源码)
查看>>
Objective-C实现linear algebra线性代数算法(附完整源码)
查看>>
Objective-C实现linear congruential generator线性同余发生器算法(附完整源码)
查看>>
Objective-C实现linear discriminant analysis线性判别分析算法(附完整源码)
查看>>
Objective-C实现linear regression线性回归算法(附完整源码)
查看>>
Objective-C实现linear search线性搜索算法(附完整源码)
查看>>
Objective-C实现Linear search线性搜索算法(附完整源码)
查看>>