-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
57 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
...covery-consumer-sample/src/main/java/com/example/demo/controller/OpenFeignController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.example.demo.controller; | ||
|
||
import com.example.demo.service.EchoService; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
/** | ||
* OpenFeign 服务调用 | ||
* | ||
* @author yclimb | ||
* @date 2020/9/30 | ||
*/ | ||
@RestController | ||
public class OpenFeignController { | ||
|
||
@Autowired | ||
private EchoService echoService; | ||
|
||
@GetMapping("/feign/echo/{message}") | ||
public String feignEcho(@PathVariable String message) { | ||
return echoService.echo(message); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
nacos-discovery-consumer-sample/src/main/java/com/example/demo/service/EchoService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.example.demo.service; | ||
|
||
import org.springframework.cloud.openfeign.FeignClient; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
|
||
/** | ||
* 指向服务提供者应用 | ||
* | ||
* @author yclimb | ||
* @date 2020/9/30 | ||
*/ | ||
@FeignClient("nacos-discovery-provider-sample") | ||
public interface EchoService { | ||
|
||
/** | ||
* echo(String) 方法在 Spring MVC 请求映射的方式与 nacos-discovery-provider-sample 中的 ServiceController 基本相同, | ||
* 唯一区别在于 @PathVariable 注解指定了 value 属性 “message”, | ||
* 这是因为默认情况,Java 编译器不会讲接口方法参数名添加到 Java 字节码中。 | ||
* | ||
* @param message message | ||
* @return String | ||
*/ | ||
@GetMapping("/echo/{message}") | ||
String echo(@PathVariable("message") String message); | ||
} |
2 changes: 1 addition & 1 deletion
2
...a/com/example/demo/ServiceController.java → ...le/demo/controller/ServiceController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters