1. 在.pom文件中添加openfeign的依賴
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
2.在application.properties中配置http的url地service_port=192.168.**.**:8899
3.新建一個service方法 不用寫實現類
3.1使用@FeignClient(url = "${service_port}",name = "Feign") //url為配置文件中定義的url Name可隨便自定義
3.2使用 @GetMapping、@postMapping 或者 @RequestMapping去定義的請求的類型 和 具體接口地址
3.3方法內可以傳遞需要的參數
4.在控制層注入 service 調用即可
@Autowired
private AvoidService service ;
JSONObject user = service.getUser(userId);