添加依赖
<dependency> <groupId>nxcloud.foundation</groupId> <artifactId>foundation-feign-client</artifactId></dependency>
创建 Client
package nxcloud.sample.simple.feign.client.service;
import lombok.Builder;
import lombok.Data;
import nxcloud.foundation.feign.base.response.R;
import nxcloud.foundation.feign.client.config.FeignClientConfig;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
/**
* author: sunshow.
*/
@FeignClient(value = "nxcloud-simple-gateway", configuration = FeignClientConfig.class)
public interface FeignTestClient {
@GetMapping(value = "/test/get")
R<Response> testGet();
@GetMapping(value = "/test/exception/runtime")
R<Response> testRuntimeException();
@GetMapping(value = "/test/exception/code")
R<Response> testCodeException();
@PostMapping(value = "/test/post/param")
R<String> testPostWithParam(@RequestParam("param") String param);
@PostMapping(value = "/test/post/body")
R<Response> testPostWithBody(@RequestBody Request request);
@Data
@Builder
class Request {
String param;
}
@Data
class Response {
String content;
}
}