博客
关于我
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实现使用 radix-2 快速傅里叶变换的快速多项式乘法算法(附完整源码)
查看>>
Objective-C实现使用 ziggurat() 作为 OpenMP 并行程序中的随机数生成器 (RNG)(附完整源码)
查看>>
Objective-C实现使用DisjointSet 检测无向循环算法(附完整源码)
查看>>
Objective-C实现使用Prim算法确定图的最小生成树算法(附完整源码)
查看>>
Objective-C实现使用二元运算符将两个数字相加fullAdder算法(附完整源码)
查看>>
Objective-C实现使用分而治之找到单峰列表的峰值算法(附完整源码)
查看>>
Objective-C实现使用数组实现约瑟夫环(附完整源码)
查看>>
Objective-C实现使用矩阵求幂的第 n 个斐波那契算法(附完整源码)
查看>>
Objective-C实现使用管道重定向进程输入输出(附完整源码)
查看>>
Objective-C实现倒计时(附完整源码)
查看>>
Objective-C实现借记款项功能(附完整源码)
查看>>
Objective-C实现全年3天打渔,2天晒网(附完整源码)
查看>>
Objective-C实现八进制转十进制算法(附完整源码)
查看>>
Objective-C实现共享内存(附完整源码)
查看>>
Objective-C实现关机、重启、注销功能的实现(附完整源代码)
查看>>
Objective-C实现关机程序(附完整源码)
查看>>
Objective-C实现关系矩阵A和B的乘积(附完整源码)
查看>>
Objective-C实现关系矩阵乘法(附完整源码)
查看>>
Objective-C实现关系矩阵乘法(附完整源码)
查看>>
Objective-C实现关键字移位字母表密码算法(附完整源码)
查看>>