File tree Expand file tree Collapse file tree 2 files changed +23
-37
lines changed
SpringBootAsync/src/main/java/com/example Expand file tree Collapse file tree 2 files changed +23
-37
lines changed Load Diff This file was deleted.
Original file line number Diff line number Diff line change 11package com .example .web ;
22
3+ import com .example .service .BasicService ;
34import org .apache .log4j .Logger ;
45import org .springframework .beans .factory .annotation .Autowired ;
6+ import org .springframework .http .ResponseEntity ;
7+ import org .springframework .util .concurrent .ListenableFuture ;
58import org .springframework .web .bind .annotation .GetMapping ;
9+ import org .springframework .web .bind .annotation .PathVariable ;
610import org .springframework .web .bind .annotation .RestController ;
7-
8- import com .example .service .BasicService ;
11+ import org .springframework .web .client .AsyncRestTemplate ;
912
1013@ RestController
1114public class BasicController {
1215
13- @ Autowired
14- private BasicService service ;
15-
16+ @ Autowired BasicService service ;
17+
18+ @ Autowired AsyncRestTemplate asyncRestTemplate ;
19+
1620 private static final Logger logger = Logger .getLogger (BasicController .class );
1721
1822 @ GetMapping ("/async" )
@@ -32,4 +36,18 @@ public String goSync() {
3236 logger .info ("==================================" );
3337 return str ;
3438 }
39+
40+ @ GetMapping ("/{userName}" )
41+ public void getRepository (@ PathVariable String userName ) {
42+ getRepositoryInfo (userName )
43+ .addCallback (
44+ System .out ::println ,
45+ System .out ::println
46+ );
47+ }
48+
49+ private ListenableFuture <ResponseEntity <String >> getRepositoryInfo (String userName ) {
50+ return asyncRestTemplate
51+ .getForEntity ("https://api.github.com/users/" + userName + "/repos" , String .class );
52+ }
3553}
You can’t perform that action at this time.
0 commit comments