Skip to content

Commit 2437e26

Browse files
committed
add refactoring
1 parent 4d20389 commit 2437e26

File tree

2 files changed

+23
-37
lines changed

2 files changed

+23
-37
lines changed

SpringBootAsync/src/main/java/com/example/component/InitRunner.java

Lines changed: 0 additions & 32 deletions
This file was deleted.

SpringBootAsync/src/main/java/com/example/web/BasicController.java

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
11
package com.example.web;
22

3+
import com.example.service.BasicService;
34
import org.apache.log4j.Logger;
45
import org.springframework.beans.factory.annotation.Autowired;
6+
import org.springframework.http.ResponseEntity;
7+
import org.springframework.util.concurrent.ListenableFuture;
58
import org.springframework.web.bind.annotation.GetMapping;
9+
import org.springframework.web.bind.annotation.PathVariable;
610
import org.springframework.web.bind.annotation.RestController;
7-
8-
import com.example.service.BasicService;
11+
import org.springframework.web.client.AsyncRestTemplate;
912

1013
@RestController
1114
public 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
}

0 commit comments

Comments
 (0)