本文共 1527 字,大约阅读时间需要 5 分钟。
??????????????Spring Initializer??????Spring Boot??????Web Starter????????????????????spring-boot-starter-web???pom.xml?????Spring Boot??????????????????
?Spring Boot??????????????@EnableAsync??????????????????????????????????????????????
@EnableAsync@SpringBootApplicationpublic class Springboot12TaskApplication { public static void main(String[] args) { SpringApplication.run(Springboot12TaskApplication.class, args); }} ?????????????????????????????????Service??
??@Service????????????@Async????????????????????
@Servicepublic class AsyncService { @Async public void hello() { try { Thread.sleep(3000); } catch (InterruptedException e) { e.printStackTrace(); } System.out.println("?????..."); }} ??????Spring Boot??????????????????????????????????????????????????????
????????AsyncController???@RestController?????AsyncService???@GetMapping???????????????
@RestControllerpublic class AsyncController { @Resource AsyncService asyncService; @GetMapping("/hello") public String hello() { asyncService.hello(); return "success"; }} ?????????Service????HTTP???????????????????????
????Spring Boot??????????http://localhost:8080/hello?????Postman?curl?????????
???????????????3????????????????????????????????????
??????????????????Spring Boot?????Web??????????????????????????????????????????????????????????????????
转载地址:http://jwz.baihongyu.com/