{"id":32830,"date":"2025-04-26T01:10:50","date_gmt":"2025-04-25T17:10:50","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/32830.html"},"modified":"2025-04-26T01:10:50","modified_gmt":"2025-04-25T17:10:50","slug":"spring-cloud%e4%b9%8b%e8%bf%9c%e7%a8%8b%e8%b0%83%e7%94%a8openfeign%e6%9c%80%e4%bd%b3%e5%ae%9e%e8%b7%b5","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/32830.html","title":{"rendered":"Spring Cloud\u4e4b\u8fdc\u7a0b\u8c03\u7528OpenFeign\u6700\u4f73\u5b9e\u8df5"},"content":{"rendered":"<p style=\"text-align:center\"><img decoding=\"async\" alt=\"\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250425171043-680bc213d25f2.gif\" \/><\/p>\n<p id=\"main-toc\">\u76ee\u5f55<\/p>\n<p id=\"-toc\" style=\"margin-left:80px\">\n<p id=\"OpenFeign%E6%9C%80%E4%BD%B3%E5%AE%9E%E8%B7%B5-toc\" style=\"margin-left:80px\">OpenFeign\u6700\u4f73\u5b9e\u8df5<\/p>\n<p id=\"%E9%97%AE%E9%A2%98%E5%BC%95%E5%85%A5-toc\" style=\"margin-left:120px\">\u95ee\u9898\u5f15\u5165<\/p>\n<p id=\"Feign%20%E7%BB%A7%E6%89%BF%E6%96%B9%E5%BC%8F-toc\" style=\"margin-left:120px\">Feign \u7ee7\u627f\u65b9\u5f0f<\/p>\n<p id=\"%E5%88%9B%E5%BB%BAModule-toc\" style=\"margin-left:160px\">\u521b\u5efaModule<\/p>\n<p id=\"%E5%BC%95%E5%85%A5%E4%BE%9D%E8%B5%96-toc\" style=\"margin-left:160px\">\u5f15\u5165\u4f9d\u8d56<\/p>\n<p id=\"%E7%BC%96%E5%86%99%E6%8E%A5%E5%8F%A3-toc\" style=\"margin-left:160px\">\u7f16\u5199\u63a5\u53e3<\/p>\n<p id=\"%E6%89%93Jar%E5%8C%85-toc\" style=\"margin-left:160px\">\u6253Jar\u5305<\/p>\n<p id=\"%E6%9C%8D%E5%8A%A1%E6%8F%90%E4%BE%9B%E6%96%B9-toc\" style=\"margin-left:160px\">\u670d\u52a1\u63d0\u4f9b\u65b9<\/p>\n<p id=\"%E6%9C%8D%E5%8A%A1%E6%B6%88%E8%B4%B9%E6%96%B9-toc\" style=\"margin-left:160px\">\u670d\u52a1\u6d88\u8d39\u65b9<\/p>\n<p id=\"%E5%90%AF%E5%8A%A8%E6%9C%8D%E5%8A%A1%E5%B9%B6%E8%AE%BF%E9%97%AE-toc\" style=\"margin-left:160px\">\u542f\u52a8\u670d\u52a1\u5e76\u8bbf\u95ee<\/p>\n<p id=\"Feign%20%E6%8A%BD%E5%8F%96%E6%96%B9%E5%BC%8F-toc\" style=\"margin-left:120px\">Feign \u62bd\u53d6\u65b9\u5f0f<\/p>\n<p id=\"%E5%88%9B%E5%BB%BAModule-toc\" style=\"margin-left:160px\">\u521b\u5efaModule<\/p>\n<p id=\"%E5%BC%95%E5%85%A5%E4%BE%9D%E8%B5%96-toc\" style=\"margin-left:160px\">\u5f15\u5165\u4f9d\u8d56<\/p>\n<p id=\"%E7%BC%96%E5%86%99%E6%8E%A5%E5%8F%A3-toc\" style=\"margin-left:160px\">\u7f16\u5199\u63a5\u53e3<\/p>\n<p id=\"%E6%89%93Jar%E5%8C%85-toc\" style=\"margin-left:160px\">\u6253Jar\u5305<\/p>\n<p id=\"%E6%9C%8D%E5%8A%A1%E6%B6%88%E8%B4%B9%E6%96%B9-toc\" style=\"margin-left:160px\">\u670d\u52a1\u6d88\u8d39\u65b9<\/p>\n<p id=\"%E5%90%AF%E5%8A%A8%E6%9C%8D%E5%8A%A1%E5%B9%B6%E8%AE%BF%E9%97%AE-toc\" style=\"margin-left:160px\">\u542f\u52a8\u670d\u52a1\u5e76\u8bbf\u95ee<\/p>\n<p id=\"%E6%9C%8D%E5%8A%A1%E9%83%A8%E7%BD%B2-toc\" style=\"margin-left:120px\">\u670d\u52a1\u90e8\u7f72<\/p>\n<p id=\"%E4%BF%AE%E6%94%B9pom.xml%E6%96%87%E4%BB%B6-toc\" style=\"margin-left:160px\">\u4fee\u6539pom.xml\u6587\u4ef6<\/p>\n<p id=\"%E8%A7%82%E5%AF%9FNacos%E6%8E%A7%E5%88%B6%E5%8F%B0-toc\" style=\"margin-left:160px\">\u89c2\u5bdfNacos\u63a7\u5236\u53f0<\/p>\n<p id=\"%E8%BF%9C%E7%A8%8B%E8%AE%BF%E9%97%AE-toc\" style=\"margin-left:160px\">\u8fdc\u7a0b\u8bbf\u95ee<\/p>\n<hr id=\"hr-toc\" \/>\n<h4 id=\"OpenFeign%E6%9C%80%E4%BD%B3%E5%AE%9E%E8%B7%B5\">OpenFeign\u6700\u4f73\u5b9e\u8df5<\/h4>\n<h5 id=\"%E9%97%AE%E9%A2%98%E5%BC%95%E5%85%A5\">\u95ee\u9898\u5f15\u5165<\/h5>\n<p><span style=\"color:#956fe7\">\u6700\u4f73\u5b9e\u8df5, \u5176\u5b9e\u4e5f\u5c31\u662f\u7ecf\u8fc7\u5386\u53f2\u7684\u8fed\u4ee3, \u5728\u9879\u2f6c\u4e2d\u7684\u5b9e\u8df5\u8fc7\u7a0b\u4e2d, \u603b\u7ed3\u51fa\u6765\u7684\u6700\u597d\u7684\u4f7f\u2f64\u2f45\u5f0f.<\/span><\/p>\n<p>\u901a\u8fc7\u89c2\u5bdf, \u6211\u4eec\u4e5f\u80fd\u770b\u51fa\u6765, Feign\u7684\u5ba2\u6237\u7aef\u4e0e\u670d\u52a1\u63d0\u4f9b\u8005\u7684controller\u4ee3\u7801\u2fae\u5e38\u76f8\u4f3c&#xff1a;<\/p>\n<p>Feign\u5ba2\u6237\u7aef<\/p>\n<p>&#064;FeignClient(value &#061; &#034;product-service&#034;,path &#061; &#034;\/product&#034;)<br \/>\npublic interface ProductApi {<br \/>\n    &#064;RequestMapping(&#034;\/{productId}&#034;)<br \/>\n    ProductInfo getProductById(&#064;PathVariable(&#034;productId&#034;) Integer productId);<br \/>\n} <\/p>\n<p>\u670d\u52a1\u63d0\u4f9b\u65b9Controller<\/p>\n<p>&#064;RequestMapping(&#034;\/product&#034;)<br \/>\n&#064;RestController<br \/>\npublic class ProductController {<br \/>\n    &#064;Autowired<br \/>\n    private ProductService productService;<\/p>\n<p>    &#064;RequestMapping(&#034;\/{productId}&#034;)<br \/>\n    public ProductInfo getProductById(&#064;PathVariable(&#034;productId&#034;) Integer productId){<br \/>\n        return productService.selectProductById(productId);<br \/>\n    }<br \/>\n} <\/p>\n<p>\u90a3\u4e48\u6709\u6ca1\u6709\u2f00\u79cd\u2f45\u6cd5\u53ef\u4ee5\u7b80\u5316\u8fd9\u79cd\u5199\u6cd5\u5462?<\/p>\n<h5 id=\"Feign%20%E7%BB%A7%E6%89%BF%E6%96%B9%E5%BC%8F\">Feign \u7ee7\u627f\u65b9\u5f0f<\/h5>\n<p>Feign \u2f40\u6301\u7ee7\u627f\u7684\u2f45\u5f0f, \u6211\u4eec\u53ef\u4ee5\u628a\u2f00\u4e9b\u5e38\u2ec5\u7684\u64cd\u4f5c\u5c01\u88c5\u5230\u63a5\u2f1d\u2fa5. \u6211\u4eec\u53ef\u4ee5\u5b9a\u4e49\u597d\u2f00\u4e2a\u63a5\u2f1d, \u670d\u52a1\u63d0\u4f9b\u2f45\u5b9e\u73b0\u8fd9\u4e2a\u63a5\u2f1d, \u670d\u52a1\u6d88\u8d39\u2f45\u7f16\u5199Feign \u63a5\u2f1d\u7684\u65f6\u5019, \u76f4\u63a5\u7ee7\u627f\u8fd9\u4e2a\u63a5\u53e3\u3002<\/p>\n<h6 id=\"%E5%88%9B%E5%BB%BAModule\">\u521b\u5efaModule<\/h6>\n<p>\u63a5\u2f1d\u53ef\u4ee5\u653e\u5728\u2f00\u4e2a\u516c\u5171\u7684Jar\u5305\u2fa5, \u4f9b\u670d\u52a1\u63d0\u4f9b\u2f45\u548c\u670d\u52a1\u6d88\u8d39\u2f45\u4f7f\u2f64.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"475\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250425171044-680bc2140cccd.png\" width=\"521\" \/><\/p>\n<h6 id=\"%E5%BC%95%E5%85%A5%E4%BE%9D%E8%B5%96\">\u5f15\u5165\u4f9d\u8d56<\/h6>\n<p> &lt;dependencies&gt;<br \/>\n    &lt;dependency&gt;<br \/>\n        &lt;groupId&gt;org.springframework.boot&lt;\/groupId&gt;<br \/>\n        &lt;artifactId&gt;spring-boot-starter-web&lt;\/artifactId&gt;<br \/>\n    &lt;\/dependency&gt;<br \/>\n    &lt;dependency&gt;<br \/>\n        &lt;groupId&gt;org.springframework.cloud&lt;\/groupId&gt;<br \/>\n        &lt;artifactId&gt;spring-cloud-starter-openfeign&lt;\/artifactId&gt;<br \/>\n    &lt;\/dependency&gt;<br \/>\n&lt;\/dependencies&gt; <\/p>\n<h6 id=\"%E7%BC%96%E5%86%99%E6%8E%A5%E5%8F%A3\">\u7f16\u5199\u63a5\u53e3<\/h6>\n<p>\u628a\u4e4b\u524dProductApi\u7684\u5185\u5bb9\u79fb\u52a8\u5230Module\u4e2d\u7684ProductInterface\u63a5\u53e3\u4e2d&#xff1a;<\/p>\n<p>package api;<\/p>\n<p>import model.ProductInfo;<br \/>\nimport org.springframework.cloud.openfeign.SpringQueryMap;<br \/>\nimport org.springframework.web.bind.annotation.PathVariable;<br \/>\nimport org.springframework.web.bind.annotation.RequestBody;<br \/>\nimport org.springframework.web.bind.annotation.RequestMapping;<br \/>\nimport org.springframework.web.bind.annotation.RequestParam;<\/p>\n<p>public interface ProductInterface {<br \/>\n    &#064;RequestMapping(&#034;\/{productId}&#034;)<br \/>\n    ProductInfo getProductById(&#064;PathVariable(&#034;productId&#034;) Integer productId);<\/p>\n<p>    &#064;RequestMapping(&#034;\/p1&#034;)<br \/>\n    String p1(&#064;RequestParam(&#034;id&#034;) Integer id);<\/p>\n<p>    &#064;RequestMapping(&#034;\/p2&#034;)<br \/>\n    String p2(&#064;RequestParam(&#034;id&#034;) Integer id, &#064;RequestParam(&#034;name&#034;) String name);<\/p>\n<p>    &#064;RequestMapping(&#034;\/p3&#034;)<br \/>\n    String p3(&#064;SpringQueryMap ProductInfo productInfo);<\/p>\n<p>    &#064;RequestMapping(&#034;\/p4&#034;)<br \/>\n    String p4(&#064;RequestBody ProductInfo productInfo);<br \/>\n} <\/p>\n<p>\u628a\u4e4b\u524dProductInfo\u7684\u5185\u5bb9\u79fb\u52a8\u5230Module\u4e2d&#xff1a;<\/p>\n<p>package model;<\/p>\n<p>import lombok.Data;<\/p>\n<p>import java.util.Date;<\/p>\n<p>&#064;Data<br \/>\npublic class ProductInfo {<br \/>\n    private Integer id;<br \/>\n    private String productName;<br \/>\n    private Integer productPrice;<br \/>\n    private Integer state;<br \/>\n    private Date createTime;<br \/>\n    private Date updateTime;<br \/>\n} <\/p>\n<p>\u76ee\u5f55\u7ed3\u6784\u5982\u4e0b&#xff1a;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"279\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250425171044-680bc21462d15.png\" width=\"315\" \/><\/p>\n<h6 id=\"%E6%89%93Jar%E5%8C%85\">\u6253Jar\u5305<\/h6>\n<p>\u901a\u8fc7Maven\u6253\u5305<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"493\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250425171044-680bc2149083e.png\" width=\"438\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"527\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250425171044-680bc214c5e47.png\" width=\"1200\" \/><\/p>\n<p>\u89c2\u5bdfMaven\u672c\u5730\u4ed3\u5e93, Jar\u5305\u662f\u5426\u6253\u6210\u529f&#xff1a;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"162\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250425171045-680bc2154a54d.png\" width=\"788\" \/><\/p>\n<h6 id=\"%E6%9C%8D%E5%8A%A1%E6%8F%90%E4%BE%9B%E6%96%B9\">\u670d\u52a1\u63d0\u4f9b\u65b9<\/h6>\n<p>\u670d\u52a1\u63d0\u4f9b\u2f45\u5b9e\u73b0\u63a5\u53e3 ProductInterface<\/p>\n<p>package product.controller;<\/p>\n<p>import api.ProductInterface;<br \/>\nimport model.ProductInfo;<br \/>\nimport org.springframework.beans.factory.annotation.Autowired;<br \/>\nimport org.springframework.web.bind.annotation.PathVariable;<br \/>\nimport org.springframework.web.bind.annotation.RequestBody;<br \/>\nimport org.springframework.web.bind.annotation.RequestMapping;<br \/>\nimport org.springframework.web.bind.annotation.RestController;<br \/>\nimport product.service.ProductService;<\/p>\n<p>&#064;RequestMapping(&#034;\/product&#034;)<br \/>\n&#064;RestController<br \/>\npublic class ProductController implements ProductInterface {<br \/>\n    &#064;Autowired<br \/>\n    private ProductService productService;<\/p>\n<p>    &#064;RequestMapping(&#034;\/{productId}&#034;)<br \/>\n    public ProductInfo getProductById(&#064;PathVariable(&#034;productId&#034;) Integer productId){<br \/>\n        return productService.selectProductById(productId);<br \/>\n    }<\/p>\n<p>    &#064;RequestMapping(&#034;\/p1&#034;)<br \/>\n    public String p1(Integer id){<br \/>\n        return &#034;product-service \u63a5\u6536\u5230\u53c2\u6570, id:&#034;&#043;id;<br \/>\n    }<br \/>\n    &#064;RequestMapping(&#034;\/p2&#034;)<br \/>\n    public String p2(Integer id, String name){<br \/>\n        return &#034;product-service \u63a5\u6536\u5230\u53c2\u6570, id:&#034;&#043;id&#043;&#034;,name:&#034;&#043;name;<br \/>\n    }<br \/>\n    &#064;RequestMapping(&#034;\/p3&#034;)<br \/>\n    public String p3(ProductInfo productInfo){<br \/>\n        return &#034;product-service \u63a5\u6536\u5230\u53c2\u6570: productInfo&#034;&#043;productInfo.toString();<br \/>\n    }<\/p>\n<p>    &#064;RequestMapping(&#034;\/p4&#034;)<br \/>\n    public String p4(&#064;RequestBody ProductInfo productInfo){<br \/>\n        return &#034;product-service \u63a5\u6536\u5230\u53c2\u6570: productInfo&#034;&#043;productInfo.toString();<br \/>\n    }<br \/>\n} <\/p>\n<h6 id=\"%E6%9C%8D%E5%8A%A1%E6%B6%88%E8%B4%B9%E6%96%B9\">\u670d\u52a1\u6d88\u8d39\u65b9<\/h6>\n<p>\u670d\u52a1\u6d88\u8d39\u2f45\u7ee7\u627fProductInterface<\/p>\n<p>package order.api;<\/p>\n<p>import api.ProductInterface;<br \/>\nimport org.springframework.cloud.openfeign.FeignClient;<\/p>\n<p>&#064;FeignClient(value &#061; &#034;product-service&#034;,path &#061; &#034;\/product&#034;)<br \/>\npublic interface ProductApi extends ProductInterface {<br \/>\n} <\/p>\n<h6 id=\"%E5%90%AF%E5%8A%A8%E6%9C%8D%E5%8A%A1%E5%B9%B6%E8%AE%BF%E9%97%AE\">\u542f\u52a8\u670d\u52a1\u5e76\u8bbf\u95ee<\/h6>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"309\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250425171045-680bc2157b086.png\" width=\"345\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"144\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250425171045-680bc215a9e7c.png\" width=\"1200\" \/><\/p>\n<h5 id=\"Feign%20%E6%8A%BD%E5%8F%96%E6%96%B9%E5%BC%8F\">Feign \u62bd\u53d6\u65b9\u5f0f<\/h5>\n<p>\u5b98\u2f45\u63a8\u8350Feign\u7684\u4f7f\u2f64\u2f45\u5f0f\u4e3a\u7ee7\u627f\u7684\u2f45\u5f0f, \u4f46\u662f\u4f01\u4e1a\u5f00\u53d1\u4e2d, \u66f4\u591a\u662f\u628aFeign\u63a5\u2f1d\u62bd\u53d6\u4e3a\u2f00\u4e2a\u72ec\u2f74\u7684\u6a21\u5757(\u505a\u6cd5\u548c\u7ee7\u627f\u76f8\u4f3c, \u4f46\u7406\u5ff5\u4e0d\u540c).<\/p>\n<p>\u64cd\u4f5c\u2f45\u6cd5: \u5c06Feign\u7684Client\u62bd\u53d6\u4e3a\u2f00\u4e2a\u72ec\u2f74\u7684\u6a21\u5757, \u5e76\u628a\u6d89\u53ca\u5230\u7684\u5b9e\u4f53\u7c7b\u7b49\u90fd\u653e\u5728\u8fd9\u4e2a\u6a21\u5757\u4e2d, \u6253\u6210\u2f00\u4e2aJar. \u670d\u52a1\u6d88\u8d39\u2f45\u53ea\u9700\u8981\u4f9d\u8d56\u8be5Jar\u5305\u5373\u53ef. \u8fd9\u79cd\u2f45\u5f0f\u5728\u4f01\u4e1a\u4e2d\u2f50\u8f83\u5e38\u2ec5, Jar\u5305\u901a\u5e38\u7531\u670d\u52a1\u63d0\u4f9b\u2f45\u6765\u5b9e\u73b0.\u00a0<\/p>\n<h6>\u521b\u5efaModule<\/h6>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"897\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250425171045-680bc215de21c.png\" width=\"984\" \/><\/p>\n<h6>\u5f15\u5165\u4f9d\u8d56<\/h6>\n<p> &lt;dependency&gt;<br \/>\n    &lt;groupId&gt;org.springframework.cloud&lt;\/groupId&gt;<br \/>\n    &lt;artifactId&gt;spring-cloud-starter-openfeign&lt;\/artifactId&gt;<br \/>\n&lt;\/dependency&gt; <\/p>\n<h6>\u7f16\u5199\u63a5\u53e3<\/h6>\n<p>\u628a\u4e4b\u524dProductApi\u7684\u5185\u5bb9\u79fb\u52a8\u5230Module\u4e2d\u7684ProductInterface\u63a5\u53e3\u4e2d&#xff1a;<\/p>\n<p>package api;<\/p>\n<p>import model.ProductInfo;<br \/>\nimport org.springframework.cloud.openfeign.SpringQueryMap;<br \/>\nimport org.springframework.web.bind.annotation.PathVariable;<br \/>\nimport org.springframework.web.bind.annotation.RequestBody;<br \/>\nimport org.springframework.web.bind.annotation.RequestMapping;<br \/>\nimport org.springframework.web.bind.annotation.RequestParam;<\/p>\n<p>public interface ProductInterface {<br \/>\n    &#064;RequestMapping(&#034;\/{productId}&#034;)<br \/>\n    ProductInfo getProductById(&#064;PathVariable(&#034;productId&#034;) Integer productId);<\/p>\n<p>    &#064;RequestMapping(&#034;\/p1&#034;)<br \/>\n    String p1(&#064;RequestParam(&#034;id&#034;) Integer id);<\/p>\n<p>    &#064;RequestMapping(&#034;\/p2&#034;)<br \/>\n    String p2(&#064;RequestParam(&#034;id&#034;) Integer id, &#064;RequestParam(&#034;name&#034;) String name);<\/p>\n<p>    &#064;RequestMapping(&#034;\/p3&#034;)<br \/>\n    String p3(&#064;SpringQueryMap ProductInfo productInfo);<\/p>\n<p>    &#064;RequestMapping(&#034;\/p4&#034;)<br \/>\n    String p4(&#064;RequestBody ProductInfo productInfo);<br \/>\n} <\/p>\n<p>\u628a\u4e4b\u524dProductInfo\u7684\u5185\u5bb9\u79fb\u52a8\u5230Module\u4e2d&#xff1a;<\/p>\n<p>package model;<\/p>\n<p>import lombok.Data;<\/p>\n<p>import java.util.Date;<\/p>\n<p>&#064;Data<br \/>\npublic class ProductInfo {<br \/>\n    private Integer id;<br \/>\n    private String productName;<br \/>\n    private Integer productPrice;<br \/>\n    private Integer state;<br \/>\n    private Date createTime;<br \/>\n    private Date updateTime;<br \/>\n} <\/p>\n<p>\u76ee\u5f55\u7ed3\u6784\u5982\u4e0b&#xff1a;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"279\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250425171044-680bc21462d15.png\" width=\"315\" \/><\/p>\n<h6>\u6253Jar\u5305<\/h6>\n<p>\u901a\u8fc7Maven\u6253\u5305<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"596\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250425171046-680bc2163eecd.png\" width=\"424\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"483\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250425171046-680bc21674b88.png\" width=\"1200\" \/><\/p>\n<p>\u89c2\u5bdfMaven\u672c\u5730\u4ed3\u5e93, Jar\u5305\u662f\u5426\u6253\u6210\u529f&#xff1a;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"153\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250425171046-680bc216c892e.png\" width=\"689\" \/><\/p>\n<h6>\u670d\u52a1\u6d88\u8d39\u65b9<\/h6>\n<p>\u5220\u9664ProductInfo\u548cProductApi<\/p>\n<p>\u5f15\u5165\u4f9d\u8d56<\/p>\n<p> &lt;dependency&gt;<br \/>\n    &lt;groupId&gt;com.wmh&lt;\/groupId&gt;<br \/>\n    &lt;artifactId&gt;product-api&lt;\/artifactId&gt;<br \/>\n    &lt;version&gt;1.0-SNAPSHOT&lt;\/version&gt;<br \/>\n    &lt;scope&gt;compile&lt;\/scope&gt;<br \/>\n&lt;\/dependency&gt; <\/p>\n<p>\u6307\u5b9a\u626b\u63cf\u7c7b<\/p>\n<p>\u4e0b\u9762\u6211\u4eec\u4f7f\u7528&#064;EnableFeignClients(clients &#061; {ProductApi.class})\u6765\u6307\u5b9a\u626b\u63cf\u7c7b&#xff0c;<\/p>\n<p>\u5f53\u7136\u4e5f\u53ef\u4ee5\u4f7f\u7528&#064;EnableFeignClients(basePackages &#061; {&#034;api&#034;})\u6307\u5b9a\u626b\u63cf\u7c7b\u3002<\/p>\n<p>package order;<\/p>\n<p>import api.ProductApi;<br \/>\nimport org.springframework.boot.SpringApplication;<br \/>\nimport org.springframework.boot.autoconfigure.SpringBootApplication;<br \/>\nimport org.springframework.cloud.openfeign.EnableFeignClients;<\/p>\n<p>&#064;EnableFeignClients(clients &#061; {ProductApi.class})<br \/>\n&#064;SpringBootApplication<br \/>\npublic class OrderServiceApplication {<br \/>\n    public static void main(String[] args) {<br \/>\n        SpringApplication.run(OrderServiceApplication.class, args);<br \/>\n    }<br \/>\n} <\/p>\n<p>\u5982\u679c\u4e0d\u6307\u5b9a\u626b\u63cf\u7c7b\u7684\u8bdd&#xff0c;\u8fd0\u884c\u7a0b\u5e8f\u4f1a\u5931\u8d25\u5e76\u62a5\u9519&#xff1a;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"532\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250425171046-680bc216f2764.jpg\" width=\"1200\" \/><\/p>\n<p>\u539f\u56e0\u662f\u56e0\u4e3aorder-service\u7684\u542f\u52a8\u7c7bOrderServiceApplication\u53ea\u4f1a\u626b\u63cf\u542f\u52a8\u7c7b\u6240\u5728\u76ee\u5f55&#xff0c;\u800cProductApi\u5e76\u4e0d\u5728\u5176\u626b\u63cf\u8def\u5f84\u5185&#xff0c;\u56e0\u6b64\u9700\u8981\u6307\u5b9a\u626b\u63cf\u7c7b\u3002<\/p>\n<h6>\u542f\u52a8\u670d\u52a1\u5e76\u8bbf\u95ee<\/h6>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"342\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250425171047-680bc217642c1.png\" width=\"394\" \/><\/p>\n<h5 id=\"%E6%9C%8D%E5%8A%A1%E9%83%A8%E7%BD%B2\">\u670d\u52a1\u90e8\u7f72<\/h5>\n<p>1. \u4fee\u6539\u6570\u636e\u5e93, Nacos\u7b49\u76f8\u5173\u914d\u7f6e 2. \u5bf9\u4e24\u4e2a\u670d\u52a1\u8fdb\u2f8f\u6253\u5305 Maven\u6253\u5305\u9ed8\u8ba4\u662f\u4ece\u8fdc\u7a0b\u4ed3\u5e93\u4e0b\u8f7d\u7684, product-api \u8fd9\u4e2a\u5305\u5728\u672c\u5730, \u6709\u4ee5\u4e0b\u89e3\u51b3\u2f45\u6848&#xff1a;<\/p>\n<p>\u25e6 \u4e0a\u4f20\u5230Maven\u4e2d\u592e\u4ed3\u5e93(\u2f50\u8f83\u2fc7\u70e6)[\u4e0d\u63a8\u8350] \u25e6 \u642d\u5efaMaven\u79c1\u670d, \u4e0a\u4f20Jar\u5305\u5230\u79c1\u670d[\u4f01\u4e1a\u63a8\u8350] \u25e6 \u4ece\u672c\u5730\u8bfb\u53d6Jar\u5305[\u4e2a\u2f08\u5b66\u4e60\u9636\u6bb5\u63a8\u8350]<\/p>\n<p>\u524d\u4e24\u79cd\u2f45\u6cd5\u2f50\u8f83\u590d\u6742, \u54b1\u4eec\u4f7f\u2f64\u7b2c\u4e09\u79cd\u2f45\u5f0f\u3002<\/p>\n<h6 id=\"%E4%BF%AE%E6%94%B9pom.xml%E6%96%87%E4%BB%B6\">\u4fee\u6539pom.xml\u6587\u4ef6<\/h6>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"486\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250425171047-680bc21794c59.png\" width=\"1200\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"280\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250425171047-680bc217e7c5d.png\" width=\"736\" \/><\/p>\n<p>\u5982\u679c\u4e0d\u914d\u7f6e\u4e0a\u56fe\u6240\u793a\u7684\u4e00\u4e0b\u5185\u5bb9&#xff0c;\u9879\u76ee\u542f\u52a8\u4f1a\u5931\u8d25\u5e76\u62a5\u9519&#xff1a;<\/p>\n<p> &lt;configuration&gt;<br \/>\n    &lt;includeSystemScope&gt;true&lt;\/includeSystemScope&gt;<br \/>\n&lt;\/configuration&gt; <\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"129\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250425171048-680bc218209e2.png\" width=\"777\" \/><\/p>\n<p>3. \u4e0a\u4f20jar\u5230Linux\u670d\u52a1\u5668 4. \u542f\u52a8Nacos \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u542f\u52a8\u524d\u6700\u597d\u628adata\u6570\u636e\u5220\u9664\u6389. 5. \u542f\u52a8\u670d\u52a1<\/p>\n<p>#\u540e\u53f0\u542f\u52a8order-service, \u5e76\u8bbe\u7f6e\u8f93\u51fa\u2f47\u5fd7\u5230logs\/order.log nohup java -jar order-service.jar &gt;logs\/order.log &amp;<\/p>\n<p> #\u540e\u53f0\u542f\u52a8product-service, \u5e76\u8bbe\u7f6e\u8f93\u51fa\u2f47\u5fd7\u5230logs\/order.log nohup java -jar product-service.jar &gt;logs\/product-9090.log &amp;<\/p>\n<p> #\u542f\u52a8\u5b9e\u4f8b, \u6307\u5b9a\u7aef\u2f1d\u53f7\u4e3a9091 nohup java -jar product-service.jar &#8211;server.port&#061;9091 &gt;logs\/product-9091.log &amp;<\/p>\n<h6 id=\"%E8%A7%82%E5%AF%9FNacos%E6%8E%A7%E5%88%B6%E5%8F%B0\">\u89c2\u5bdfNacos\u63a7\u5236\u53f0<\/h6>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"572\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250425171048-680bc2184e6c0.png\" width=\"1200\" \/><\/p>\n<h6 id=\"%E8%BF%9C%E7%A8%8B%E8%AE%BF%E9%97%AE\">\u8fdc\u7a0b\u8bbf\u95ee<\/h6>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"340\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250425171048-680bc218c8541.png\" width=\"431\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb3.2k\u6b21\uff0c\u70b9\u8d5e211\u6b21\uff0c\u6536\u85cf135\u6b21\u3002\u8be6\u89e3OpenFeign\u7684\u6700\u4f73\u5b9e\u8df5\uff0c\u5305\u62ecFeign\u7ee7\u627f\u65b9\u5f0f\u548cFeigh\u62bd\u53d6\u65b9\u5f0f\uff0c\u4ee5\u53ca\u670d\u52a1\u90e8\u7f72\u3002<\/p>\n","protected":false},"author":2,"featured_media":32811,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[99,963],"topic":[],"class_list":["post-32830","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-java","tag-spring-cloud"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Spring Cloud\u4e4b\u8fdc\u7a0b\u8c03\u7528OpenFeign\u6700\u4f73\u5b9e\u8df5 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/32830.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Spring Cloud\u4e4b\u8fdc\u7a0b\u8c03\u7528OpenFeign\u6700\u4f73\u5b9e\u8df5 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb3.2k\u6b21\uff0c\u70b9\u8d5e211\u6b21\uff0c\u6536\u85cf135\u6b21\u3002\u8be6\u89e3OpenFeign\u7684\u6700\u4f73\u5b9e\u8df5\uff0c\u5305\u62ecFeign\u7ee7\u627f\u65b9\u5f0f\u548cFeigh\u62bd\u53d6\u65b9\u5f0f\uff0c\u4ee5\u53ca\u670d\u52a1\u90e8\u7f72\u3002\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/32830.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-04-25T17:10:50+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250425171043-680bc213d25f2.gif\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/32830.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/32830.html\",\"name\":\"Spring Cloud\u4e4b\u8fdc\u7a0b\u8c03\u7528OpenFeign\u6700\u4f73\u5b9e\u8df5 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-04-25T17:10:50+00:00\",\"dateModified\":\"2025-04-25T17:10:50+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/32830.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/32830.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/32830.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Spring Cloud\u4e4b\u8fdc\u7a0b\u8c03\u7528OpenFeign\u6700\u4f73\u5b9e\u8df5\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Spring Cloud\u4e4b\u8fdc\u7a0b\u8c03\u7528OpenFeign\u6700\u4f73\u5b9e\u8df5 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/32830.html","og_locale":"zh_CN","og_type":"article","og_title":"Spring Cloud\u4e4b\u8fdc\u7a0b\u8c03\u7528OpenFeign\u6700\u4f73\u5b9e\u8df5 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb3.2k\u6b21\uff0c\u70b9\u8d5e211\u6b21\uff0c\u6536\u85cf135\u6b21\u3002\u8be6\u89e3OpenFeign\u7684\u6700\u4f73\u5b9e\u8df5\uff0c\u5305\u62ecFeign\u7ee7\u627f\u65b9\u5f0f\u548cFeigh\u62bd\u53d6\u65b9\u5f0f\uff0c\u4ee5\u53ca\u670d\u52a1\u90e8\u7f72\u3002","og_url":"https:\/\/www.wsisp.com\/helps\/32830.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-04-25T17:10:50+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250425171043-680bc213d25f2.gif"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"4 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/32830.html","url":"https:\/\/www.wsisp.com\/helps\/32830.html","name":"Spring Cloud\u4e4b\u8fdc\u7a0b\u8c03\u7528OpenFeign\u6700\u4f73\u5b9e\u8df5 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-04-25T17:10:50+00:00","dateModified":"2025-04-25T17:10:50+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/32830.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/32830.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/32830.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"Spring Cloud\u4e4b\u8fdc\u7a0b\u8c03\u7528OpenFeign\u6700\u4f73\u5b9e\u8df5"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/32830","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=32830"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/32830\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/32811"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=32830"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=32830"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=32830"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=32830"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}