博客
关于我
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实现长短期记忆人工神经网络LSTM(附完整源码)
查看>>
Objective-C实现闭式函数计算特定位置的斐波那契数fibonacciNthClosedForm算法(附完整源码)
查看>>
Objective-C实现队列(附完整源码)
查看>>
Objective-C实现阶乘递归factorialRecursive算法(附完整源码)
查看>>
Objective-C实现阿特巴希密算法(附完整源码)
查看>>
Objective-C实现随机图生成器算法(附完整源码)
查看>>
Objective-C实现随机数生成器(附完整源码)
查看>>
Objective-C实现随机生成一个 RxC 列联表(附完整源码)
查看>>