------------------客户端controller层---------------------
@RestController
public class ClientFeignController {
@Autowired
private ProductFeignInterface productFeignInterface;
@GetMapping("/msg")
public String msg() {
String msg = productFeignInterface.getMsg();
return msg;
}
}
-----------------客户端feign调用的接口-----------------------
/**
* name:被调用的服务名称
*/
@FeignClient(name = "product")
public interface ProductFeignInterface {
/**
* 根据getMapping匹配接口,与方法名无关
* @return
*/
@GetMapping("/product/getMsg")
public String getMsg();
}
------------------服务端接口-----------------------------------
@RestController
public class ServerController {
@GetMapping("/product/getMsg")
public String msg() {
return "this is product' msg 1";
}
}
--------------------------------------------------------------
注:在客户端启动类上添加 @EnableFeignClients