博客
关于我
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实现all permutations所有排列算法(附完整源码)
查看>>
Objective-C实现all subsequences所有子序列算法(附完整源码)
查看>>
Objective-C实现AlphaNumericalSort字母数字排序算法(附完整源码)
查看>>
Objective-C实现alternate disjoint set不相交集算法(附完整源码)
查看>>
Objective-C实现alternative list arrange备选列表排列算法(附完整源码)
查看>>
Objective-C实现An Armstrong number阿姆斯特朗数算法(附完整源码)
查看>>
Objective-C实现anagrams字谜算法(附完整源码)
查看>>
Objective-C实现ApproximationMonteCarlo蒙特卡洛方法计算pi值算法 (附完整源码)
查看>>
Objective-C实现area under curve曲线下面积算法(附完整源码)
查看>>
Objective-C实现arithmetic算术算法(附完整源码)
查看>>
Objective-C实现armstrong numbers阿姆斯壮数算法(附完整源码)
查看>>
Objective-C实现articulation-points(关键点)(割点)算法(附完整源码)
查看>>
Objective-C实现atoi函数功能(附完整源码)
查看>>
Objective-C实现average absolute deviation平均绝对偏差算法(附完整源码)
查看>>
Objective-C实现average mean平均数算法(附完整源码)
查看>>
Objective-C实现average median平均中位数算法(附完整源码)
查看>>
Objective-C实现average mode平均模式算法(附完整源码)
查看>>
Objective-C实现avl 树算法(附完整源码)
查看>>
Objective-C实现AvlTree树算法(附完整源码)
查看>>
Objective-C实现backtracking Jump Game回溯跳跃游戏算法(附完整源码)
查看>>