{"id":50714,"date":"2025-08-10T11:39:11","date_gmt":"2025-08-10T03:39:11","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/50714.html"},"modified":"2025-08-10T11:39:11","modified_gmt":"2025-08-10T03:39:11","slug":"%e3%80%90spring-cloud-gateway-%e5%ae%9e%e6%88%98%e7%b3%bb%e5%88%97%e3%80%91%e5%9f%ba%e7%a1%80%e7%af%87%ef%bc%9a%e8%b7%af%e7%94%b1%e3%80%81%e6%96%ad%e8%a8%80%e3%80%81%e8%bf%87%e6%bb%a4%e5%99%a8","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/50714.html","title":{"rendered":"\u3010Spring Cloud Gateway \u5b9e\u6218\u7cfb\u5217\u3011\u57fa\u7840\u7bc7\uff1a\u8def\u7531\u3001\u65ad\u8a00\u3001\u8fc7\u6ee4\u5668\u3001\u8d1f\u8f7d\u5747\u8861\u6df1\u5ea6\u89e3\u6790"},"content":{"rendered":"<h3>\u4e00\u3001\u5f15\u8a00<\/h3>\n<p>\u5728\u5fae\u670d\u52a1\u67b6\u6784\u4e2d&#xff0c;API\u7f51\u5173\u662f\u6d41\u91cf\u7684\u7edf\u4e00\u5165\u53e3&#xff0c;\u627f\u62c5\u7740\u8def\u7531\u8f6c\u53d1\u3001\u6d41\u91cf\u7ba1\u63a7\u3001\u5b89\u5168\u9632\u62a4\u7b49\u6838\u5fc3\u804c\u8d23\u3002Spring Cloud Gateway\u4f5c\u4e3aSpring\u5b98\u65b9\u63a8\u8350\u7684\u7b2c\u4e8c\u4ee3\u7f51\u5173&#xff0c;\u57fa\u4e8eSpring 5.0\u3001Spring Boot 2.0\u548cProject Reactor\u6784\u5efa&#xff0c;\u63d0\u4f9b\u4e86\u9ad8\u6027\u80fd\u7684\u54cd\u5e94\u5f0f\u7f16\u7a0b\u6a21\u578b\u548c\u4e30\u5bcc\u7684\u6269\u5c55\u80fd\u529b\u3002\u76f8\u6bd4 Zuul 1.x&#xff0c;\u5b83\u91c7\u7528\u54cd\u5e94\u5f0f\u7f16\u7a0b\u6a21\u578b&#xff0c;\u80fd\u591f\u66f4\u9ad8\u6548\u5730\u5904\u7406\u9ad8\u5e76\u53d1\u573a\u666f\u3002<br \/>\n\u672c\u6587\u5c06\u4ece\u57fa\u7840\u5165\u624b&#xff0c;\u6df1\u5165\u8bb2\u89e3\u8def\u7531\u3001\u65ad\u8a00\u3001\u8fc7\u6ee4\u5668\u3001\u8d1f\u8f7d\u5747\u8861\u53ca\u4e0eNacos\u7684\u96c6\u6210&#xff0c;\u5e2e\u52a9\u8bfb\u8005\u5feb\u901f\u638c\u63e1Gateway\u7684\u6838\u5fc3\u6280\u672f\u3002<\/p>\n<h3>\u4e8c\u3001\u6838\u5fc3\u6982\u5ff5\u4e0e\u57fa\u7840\u67b6\u6784<\/h3>\n<p>Spring Cloud Gateway \u662f Spring Cloud \u751f\u6001\u4e2d\u57fa\u4e8e WebFlux \u6784\u5efa\u7684\u9ad8\u6027\u80fd\u54cd\u5e94\u5f0f API \u7f51\u5173&#xff0c;\u5b9a\u4f4d\u4e3a\u66ff\u4ee3\u4f20\u7edf\u7684 Zuul \u7f51\u5173\u3002\u5176\u6838\u5fc3\u4ef7\u503c\u5728\u4e8e\u63d0\u4f9b\u7edf\u4e00\u7684\u8def\u7531\u7ba1\u7406\u3001\u6d41\u91cf\u63a7\u5236\u3001\u5b89\u5168\u9632\u62a4\u7b49\u529f\u80fd&#xff0c;\u6210\u4e3a\u5fae\u670d\u52a1\u67b6\u6784\u7684 \u201c\u7edf\u4e00\u5165\u53e3\u201d\u3002<\/p>\n<h4>2.1 \u6838\u5fc3\u7ec4\u4ef6<\/h4>\n<p>Spring Cloud Gateway\u7684\u6838\u5fc3\u7531\u4e09\u5927\u7ec4\u4ef6\u6784\u6210&#xff1a;<\/p>\n<ul>\n<li>\u8def\u7531&#xff08;Route&#xff09;&#xff1a;\u8def\u7531\u662f\u7f51\u5173\u7684\u57fa\u672c\u5355\u5143&#xff0c;\u5305\u542bID\u3001\u76ee\u6807URI\u3001\u65ad\u8a00\u548c\u8fc7\u6ee4\u5668\u3002<\/li>\n<li>\u65ad\u8a00&#xff08;Predicate&#xff09;&#xff1a;\u7528\u4e8e\u5339\u914d\u8bf7\u6c42\u6761\u4ef6&#xff08;\u5982\u8def\u5f84\u3001\u53c2\u6570\u3001\u65f6\u95f4\u7b49&#xff09;&#xff0c;\u51b3\u5b9a\u8bf7\u6c42\u662f\u5426\u5339\u914d\u5f53\u524d\u8def\u7531\u3002<\/li>\n<li>\u8fc7\u6ee4\u5668&#xff08;Filter&#xff09;&#xff1a;\u5206\u4e3a\u5168\u5c40\u8fc7\u6ee4\u5668&#xff08;GlobalFilter&#xff09;\u548c\u5c40\u90e8\u8fc7\u6ee4\u5668&#xff08;GatewayFilter&#xff09;&#xff0c;\u7528\u4e8e\u8bf7\u6c42\/\u54cd\u5e94\u7684\u9884\u5904\u7406\u548c\u540e\u5904\u7406\u3002<\/li>\n<\/ul>\n<h4>2.2 \u6838\u5fc3\u529f\u80fd<\/h4>\n<ul>\n<li>\u8def\u7531\u8f6c\u53d1&#xff1a;\u6839\u636e\u8bf7\u6c42\u89c4\u5219\u5c06\u8bf7\u6c42\u5206\u53d1\u5230\u4e0d\u540c\u5fae\u670d\u52a1<\/li>\n<li>\u8d1f\u8f7d\u5747\u8861&#xff1a;\u96c6\u6210 Spring Cloud LoadBalancer \u5b9e\u73b0\u52a8\u6001\u8d1f\u8f7d\u5747\u8861<\/li>\n<li>\u8fc7\u6ee4\u94fe&#xff1a;\u901a\u8fc7 Filter \u94fe\u5b9e\u73b0\u8bf7\u6c42\u9884\u5904\u7406\u548c\u54cd\u5e94\u540e\u5904\u7406<\/li>\n<li>\u52a8\u6001\u914d\u7f6e&#xff1a;\u652f\u6301\u914d\u7f6e\u4e2d\u5fc3\u52a8\u6001\u66f4\u65b0\u8def\u7531\u89c4\u5219<\/li>\n<li>\u5b89\u5168\u9632\u62a4&#xff1a;\u96c6\u6210 Spring Security \u5b9e\u73b0\u8ba4\u8bc1\u6388\u6743<\/li>\n<\/ul>\n<h4>2.3 \u6838\u5fc3\u4f18\u52bf<\/h4>\n<ul>\n<li>\u9ad8\u6027\u80fd&#xff1a;\u57fa\u4e8eWebFlux\u7684\u975e\u963b\u585eIO\u6a21\u578b&#xff0c;\u541e\u5410\u91cf\u6bd4\u4f20\u7edf\u7f51\u5173\u63d0\u534730%\u4ee5\u4e0a\u3002<\/li>\n<li>\u52a8\u6001\u8def\u7531&#xff1a;\u652f\u6301\u4eceNacos\u3001Redis\u7b49\u52a8\u6001\u52a0\u8f7d\u8def\u7531\u89c4\u5219&#xff0c;\u65e0\u9700\u91cd\u542f\u670d\u52a1\u3002<\/li>\n<li>\u4e30\u5bcc\u7684\u751f\u6001&#xff1a;\u5185\u7f6e30&#043;\u5f00\u7bb1\u5373\u7528\u7684\u8fc7\u6ee4\u5668&#xff0c;\u652f\u6301\u63d2\u4ef6\u5316\u6269\u5c55\u3002<\/li>\n<\/ul>\n<h3>\u4e09\u3001\u8def\u7531\u4e0e\u65ad\u8a00&#xff1a;\u7f51\u5173\u7684\u6838\u5fc3\u903b\u8f91<\/h3>\n<h4>3.1 \u8def\u7531\u914d\u7f6e\u57fa\u7840<\/h4>\n<p>\u8def\u7531\u914d\u7f6e\u901a\u5e38\u5728application.yml\u4e2d\u5b9a\u4e49&#xff0c;\u793a\u4f8b\u5982\u4e0b&#xff1a;<\/p>\n<p><span class=\"token key atrule\">spring<\/span><span class=\"token punctuation\">:<\/span><br \/>\n  <span class=\"token key atrule\">cloud<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token key atrule\">gateway<\/span><span class=\"token punctuation\">:<\/span><br \/>\n      <span class=\"token key atrule\">routes<\/span><span class=\"token punctuation\">:<\/span><br \/>\n        <span class=\"token punctuation\">&#8211;<\/span> <span class=\"token key atrule\">id<\/span><span class=\"token punctuation\">:<\/span> user<span class=\"token punctuation\">&#8211;<\/span>service<span class=\"token punctuation\">&#8211;<\/span>route<br \/>\n          <span class=\"token key atrule\">uri<\/span><span class=\"token punctuation\">:<\/span> lb<span class=\"token punctuation\">:<\/span>\/\/user<span class=\"token punctuation\">&#8211;<\/span>service <span class=\"token comment\"># \u8d1f\u8f7d\u5747\u8861\u670d\u52a1\u540d<\/span><br \/>\n          <span class=\"token key atrule\">predicates<\/span><span class=\"token punctuation\">:<\/span><br \/>\n            <span class=\"token punctuation\">&#8211;<\/span> Path&#061;\/api\/user\/<span class=\"token important\">**<\/span> <span class=\"token comment\"># \u8def\u5f84\u5339\u914d<\/span><br \/>\n          <span class=\"token key atrule\">filters<\/span><span class=\"token punctuation\">:<\/span><br \/>\n            <span class=\"token punctuation\">&#8211;<\/span> StripPrefix&#061;1 <span class=\"token comment\"># \u79fb\u9664\u8def\u5f84\u524d\u7f00<\/span><\/p>\n<h4>3.2 \u65ad\u8a00&#xff08;Predicate&#xff09;\u8be6\u89e3<\/h4>\n<p>\u65ad\u8a00\u662f\u8def\u7531\u5339\u914d\u7684\u6838\u5fc3\u6761\u4ef6&#xff0c;Spring Cloud Gateway\u63d0\u4f9b\u4e86\u591a\u79cd\u5185\u7f6e\u65ad\u8a00\u5de5\u5382\u3002<br \/>\n<img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/08\/20250810033909-6898145de3737.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<h5>3.2.1 \u8def\u5f84\u5339\u914d\u65ad\u8a00&#xff08;Path&#xff09;<\/h5>\n<ul>\n<li>\u8bed\u6cd5&#xff1a;Path&#061;\/path\/**<\/li>\n<li>\u793a\u4f8b&#xff1a;\u5339\u914d\u4ee5\/api\/user\/\u5f00\u5934\u7684\u6240\u6709\u8def\u5f84<\/li>\n<\/ul>\n<p><span class=\"token key atrule\">predicates<\/span><span class=\"token punctuation\">:<\/span><br \/>\n  <span class=\"token punctuation\">&#8211;<\/span> Path&#061;\/api\/user\/<span class=\"token important\">**<\/span><\/p>\n<h5>3.2.2 \u53c2\u6570\u5339\u914d\u65ad\u8a00&#xff08;Query&#xff09;<\/h5>\n<ul>\n<li>\u8bed\u6cd5&#xff1a;Query&#061;param[,regex]<\/li>\n<li>\u793a\u4f8b&#xff1a;\u5339\u914d\u5305\u542btoken\u53c2\u6570\u4e14\u503c\u4ee5Bearer_\u5f00\u5934\u7684\u8bf7\u6c42<\/li>\n<\/ul>\n<p><span class=\"token key atrule\">predicates<\/span><span class=\"token punctuation\">:<\/span><br \/>\n  <span class=\"token punctuation\">&#8211;<\/span> Query&#061;token<span class=\"token punctuation\">,<\/span>Bearer_.*<\/p>\n<h5>3.2.3 IP\u6bb5\u5339\u914d\u65ad\u8a00&#xff08;RemoteAddr&#xff09;<\/h5>\n<ul>\n<li>\u8bed\u6cd5&#xff1a;RemoteAddr&#061;192.168.1.0\/24<\/li>\n<li>\u793a\u4f8b&#xff1a;\u4ec5\u5141\u8bb8\u6765\u81ea192.168.1.0\/24\u7f51\u6bb5\u7684\u8bf7\u6c42<\/li>\n<\/ul>\n<p><span class=\"token key atrule\">predicates<\/span><span class=\"token punctuation\">:<\/span><br \/>\n  <span class=\"token punctuation\">&#8211;<\/span> RemoteAddr&#061;192.168.1.0\/24<\/p>\n<h5>3.2.4 \u65f6\u95f4\u8303\u56f4\u65ad\u8a00&#xff08;Between&#xff09;<\/h5>\n<ul>\n<li>\u8bed\u6cd5&#xff1a;Between&#061;startTime,endTime<\/li>\n<li>\u793a\u4f8b&#xff1a;\u4ec5\u57282023-01-01\u81f32023-12-31\u4e4b\u95f4\u7684\u8bf7\u6c42\u751f\u6548<\/li>\n<\/ul>\n<p><span class=\"token key atrule\">predicates<\/span><span class=\"token punctuation\">:<\/span><br \/>\n  <span class=\"token punctuation\">&#8211;<\/span> Between&#061;2023<span class=\"token punctuation\">&#8211;<\/span>01<span class=\"token punctuation\">&#8211;<\/span>01T00<span class=\"token punctuation\">:<\/span>00<span class=\"token punctuation\">:<\/span>00&#043;08<span class=\"token punctuation\">:<\/span><span class=\"token number\">00<\/span><span class=\"token punctuation\">,<\/span><span class=\"token datetime number\">2023-12-31T23:59:59&#043;08:00<\/span><\/p>\n<h5>3.2.5 \u7ec4\u5408\u65ad\u8a00&#xff08;\u903b\u8f91\u8fd0\u7b97\u7b26&#xff09;<\/h5>\n<ul>\n<li>\u8bed\u6cd5&#xff1a;\u4f7f\u7528()\u7ec4\u5408\u591a\u4e2a\u65ad\u8a00<\/li>\n<li>\u793a\u4f8b&#xff1a;\u5339\u914d\u8def\u5f84\u4e3a\/api\/user\u4e14\u8bf7\u6c42\u65b9\u6cd5\u4e3aPOST\u7684\u8bf7\u6c42<\/li>\n<\/ul>\n<p><span class=\"token key atrule\">predicates<\/span><span class=\"token punctuation\">:<\/span><br \/>\n  <span class=\"token punctuation\">&#8211;<\/span> (Path&#061;\/api\/user <span class=\"token important\">&amp;&amp;<\/span> Method&#061;POST)<\/p>\n<h5>3.2.6 \u6d41\u91cf\u5206\u914d\u65ad\u8a00&#xff08;Weight&#xff09;<\/h5>\n<ul>\n<li>\u8bed\u6cd5&#xff1a;Weight&#061;group,weight<\/li>\n<li>\u793a\u4f8b&#xff1a;\u5c0680%\u7684\u6d41\u91cf\u8f6c\u53d1\u5230weighthigh.org&#xff0c;20%\u8f6c\u53d1\u5230weightlow.org<\/li>\n<\/ul>\n<p><span class=\"token key atrule\">routes<\/span><span class=\"token punctuation\">:<\/span><br \/>\n  <span class=\"token punctuation\">&#8211;<\/span> <span class=\"token key atrule\">id<\/span><span class=\"token punctuation\">:<\/span> weight_high<br \/>\n    <span class=\"token key atrule\">uri<\/span><span class=\"token punctuation\">:<\/span> https<span class=\"token punctuation\">:<\/span>\/\/weighthigh.org<br \/>\n    <span class=\"token key atrule\">predicates<\/span><span class=\"token punctuation\">:<\/span><br \/>\n      <span class=\"token punctuation\">&#8211;<\/span> Weight&#061;group1<span class=\"token punctuation\">,<\/span><span class=\"token number\">8<\/span><br \/>\n  <span class=\"token punctuation\">&#8211;<\/span> <span class=\"token key atrule\">id<\/span><span class=\"token punctuation\">:<\/span> weight_low<br \/>\n    <span class=\"token key atrule\">uri<\/span><span class=\"token punctuation\">:<\/span> https<span class=\"token punctuation\">:<\/span>\/\/weightlow.org<br \/>\n    <span class=\"token key atrule\">predicates<\/span><span class=\"token punctuation\">:<\/span><br \/>\n      <span class=\"token punctuation\">&#8211;<\/span> Weight&#061;group1<span class=\"token punctuation\">,<\/span><span class=\"token number\">2<\/span><\/p>\n<h3>\u56db\u3001\u8fc7\u6ee4\u5668&#xff1a;\u8bf7\u6c42\u4e0e\u54cd\u5e94\u7684\u7cbe\u7ec6\u5316\u63a7\u5236<\/h3>\n<h4>4.1 \u8fc7\u6ee4\u5668\u5206\u7c7b<\/h4>\n<ul>\n<li>\u5168\u5c40\u8fc7\u6ee4\u5668&#xff08;GlobalFilter&#xff09;&#xff1a;\u5bf9\u6240\u6709\u8def\u7531\u751f\u6548&#xff0c;\u9700\u5b9e\u73b0GlobalFilter\u63a5\u53e3\u3002<\/li>\n<li>\u5c40\u90e8\u8fc7\u6ee4\u5668&#xff08;GatewayFilter&#xff09;&#xff1a;\u4ec5\u5bf9\u5f53\u524d\u8def\u7531\u751f\u6548&#xff0c;\u901a\u8fc7\u914d\u7f6e\u6587\u4ef6\u5b9a\u4e49\u3002<\/li>\n<li>\u9ed8\u8ba4\u8fc7\u6ee4\u5668&#xff08;default-filters&#xff09;&#xff1a;\u5bf9\u6240\u6709\u8def\u7531\u751f\u6548&#xff0c;\u914d\u7f6e\u5728spring.cloud.gateway.default-filters\u4e2d\u3002<\/li>\n<\/ul>\n<h4>4.2 \u5185\u7f6e\u8fc7\u6ee4\u5668\u793a\u4f8b<\/h4>\n<h5>4.2.1 \u6dfb\u52a0\u8bf7\u6c42\u5934&#xff08;AddRequestHeader&#xff09;<\/h5>\n<p><span class=\"token key atrule\">filters<\/span><span class=\"token punctuation\">:<\/span><br \/>\n  <span class=\"token punctuation\">&#8211;<\/span> AddRequestHeader&#061;X<span class=\"token punctuation\">&#8211;<\/span>Request<span class=\"token punctuation\">&#8211;<\/span>Id<span class=\"token punctuation\">,<\/span>$<span class=\"token punctuation\">{<\/span>random.uuid<span class=\"token punctuation\">}<\/span><\/p>\n<h5>4.2.2 \u79fb\u9664\u8def\u5f84\u524d\u7f00&#xff08;StripPrefix&#xff09;<\/h5>\n<p><span class=\"token key atrule\">filters<\/span><span class=\"token punctuation\">:<\/span><br \/>\n  <span class=\"token punctuation\">&#8211;<\/span> StripPrefix&#061;1 <span class=\"token comment\"># \u79fb\u9664\u7b2c\u4e00\u4e2a\u8def\u5f84\u6bb5<\/span><\/p>\n<h5>4.2.3 \u9650\u6d41\u8fc7\u6ee4\u5668&#xff08;RequestRateLimiter&#xff09;<\/h5>\n<p><span class=\"token key atrule\">filters<\/span><span class=\"token punctuation\">:<\/span><br \/>\n  <span class=\"token punctuation\">&#8211;<\/span> <span class=\"token key atrule\">name<\/span><span class=\"token punctuation\">:<\/span> RequestRateLimiter<br \/>\n    <span class=\"token key atrule\">args<\/span><span class=\"token punctuation\">:<\/span><br \/>\n      <span class=\"token key atrule\">key-resolver<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token string\">&#034;#{&#064;remoteAddrKeyResolver}&#034;<\/span> <span class=\"token comment\"># \u57fa\u4e8eIP\u9650\u6d41<\/span><br \/>\n      <span class=\"token key atrule\">redis-rate-limiter.replenishRate<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token number\">10<\/span> <span class=\"token comment\"># \u6bcf\u79d2\u751f\u621010\u4e2a\u4ee4\u724c<\/span><br \/>\n      <span class=\"token key atrule\">redis-rate-limiter.burstCapacity<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token number\">20<\/span> <span class=\"token comment\"># \u4ee4\u724c\u6876\u5bb9\u91cf<\/span><\/p>\n<h4>4.3 \u81ea\u5b9a\u4e49\u5168\u5c40\u8fc7\u6ee4\u5668<\/h4>\n<p><span class=\"token annotation punctuation\">&#064;Component<\/span><br \/>\n<span class=\"token annotation punctuation\">&#064;Order<\/span><span class=\"token punctuation\">(<\/span><span class=\"token operator\">&#8211;<\/span><span class=\"token number\">1<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token comment\">\/\/ \u4f18\u5148\u7ea7&#xff1a;\u6570\u503c\u8d8a\u5c0f&#xff0c;\u6267\u884c\u8d8a\u65e9<\/span><br \/>\n<span class=\"token keyword\">public<\/span> <span class=\"token keyword\">class<\/span> <span class=\"token class-name\">AuthFilter<\/span> <span class=\"token keyword\">implements<\/span> <span class=\"token class-name\">GlobalFilter<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token annotation punctuation\">&#064;Override<\/span><br \/>\n    <span class=\"token keyword\">public<\/span> <span class=\"token class-name\">Mono<\/span><span class=\"token generics\"><span class=\"token punctuation\">&lt;<\/span><span class=\"token class-name\">Void<\/span><span class=\"token punctuation\">&gt;<\/span><\/span> <span class=\"token function\">filter<\/span><span class=\"token punctuation\">(<\/span><span class=\"token class-name\">ServerWebExchange<\/span> exchange<span class=\"token punctuation\">,<\/span> <span class=\"token class-name\">GatewayFilterChain<\/span> chain<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token class-name\">String<\/span> token <span class=\"token operator\">&#061;<\/span> exchange<span class=\"token punctuation\">.<\/span><span class=\"token function\">getRequest<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">.<\/span><span class=\"token function\">getHeaders<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">.<\/span><span class=\"token function\">getFirst<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;Authorization&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>token <span class=\"token operator\">&#061;&#061;<\/span> <span class=\"token keyword\">null<\/span> <span class=\"token operator\">||<\/span> <span class=\"token operator\">!<\/span>token<span class=\"token punctuation\">.<\/span><span class=\"token function\">startsWith<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;Bearer &#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n            exchange<span class=\"token punctuation\">.<\/span><span class=\"token function\">getResponse<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">.<\/span><span class=\"token function\">setStatusCode<\/span><span class=\"token punctuation\">(<\/span><span class=\"token class-name\">HttpStatus<\/span><span class=\"token punctuation\">.<\/span>UNAUTHORIZED<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n            <span class=\"token keyword\">return<\/span> exchange<span class=\"token punctuation\">.<\/span><span class=\"token function\">getResponse<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">.<\/span><span class=\"token function\">setComplete<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token punctuation\">}<\/span><br \/>\n        <span class=\"token keyword\">return<\/span> chain<span class=\"token punctuation\">.<\/span><span class=\"token function\">filter<\/span><span class=\"token punctuation\">(<\/span>exchange<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span> <span class=\"token comment\">\/\/ \u653e\u884c\u8bf7\u6c42<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<h3>\u4e94\u3001\u8d1f\u8f7d\u5747\u8861&#xff1a;\u4e0eNacos\u7684\u6df1\u5ea6\u96c6\u6210<\/h3>\n<h4>5.1 \u670d\u52a1\u6ce8\u518c\u4e0e\u53d1\u73b0<\/h4>\n<li>\u5f15\u5165\u4f9d\u8d56&#xff1a;<\/li>\n<p><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>dependency<\/span><span class=\"token punctuation\">&gt;<\/span><\/span><br \/>\n    <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>groupId<\/span><span class=\"token punctuation\">&gt;<\/span><\/span>org.springframework.cloud<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>groupId<\/span><span class=\"token punctuation\">&gt;<\/span><\/span><br \/>\n    <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>artifactId<\/span><span class=\"token punctuation\">&gt;<\/span><\/span>spring-cloud-starter-gateway<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>artifactId<\/span><span class=\"token punctuation\">&gt;<\/span><\/span><br \/>\n<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>dependency<\/span><span class=\"token punctuation\">&gt;<\/span><\/span><br \/>\n<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>dependency<\/span><span class=\"token punctuation\">&gt;<\/span><\/span><br \/>\n    <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>groupId<\/span><span class=\"token punctuation\">&gt;<\/span><\/span>com.alibaba.cloud<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>groupId<\/span><span class=\"token punctuation\">&gt;<\/span><\/span><br \/>\n    <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>artifactId<\/span><span class=\"token punctuation\">&gt;<\/span><\/span>spring-cloud-starter-alibaba-nacos-discovery<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>artifactId<\/span><span class=\"token punctuation\">&gt;<\/span><\/span><br \/>\n<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>dependency<\/span><span class=\"token punctuation\">&gt;<\/span><\/span><\/p>\n<li>\u914d\u7f6eNacos&#xff1a;<\/li>\n<p><span class=\"token key atrule\">spring<\/span><span class=\"token punctuation\">:<\/span><br \/>\n  <span class=\"token key atrule\">cloud<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token key atrule\">nacos<\/span><span class=\"token punctuation\">:<\/span><br \/>\n      <span class=\"token key atrule\">discovery<\/span><span class=\"token punctuation\">:<\/span><br \/>\n        <span class=\"token key atrule\">server-addr<\/span><span class=\"token punctuation\">:<\/span> localhost<span class=\"token punctuation\">:<\/span><span class=\"token number\">8848<\/span> <span class=\"token comment\"># Nacos\u670d\u52a1\u5730\u5740<\/span><br \/>\n    <span class=\"token key atrule\">gateway<\/span><span class=\"token punctuation\">:<\/span><br \/>\n      <span class=\"token key atrule\">discovery<\/span><span class=\"token punctuation\">:<\/span><br \/>\n        <span class=\"token key atrule\">locator<\/span><span class=\"token punctuation\">:<\/span><br \/>\n          <span class=\"token key atrule\">enabled<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token boolean important\">true<\/span> <span class=\"token comment\"># \u542f\u7528\u670d\u52a1\u53d1\u73b0\u8def\u7531<\/span><br \/>\n          <span class=\"token key atrule\">lower-case-service-id<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token boolean important\">true<\/span> <span class=\"token comment\"># \u670d\u52a1\u540d\u5c0f\u5199<\/span><\/p>\n<li>\u8def\u7531\u914d\u7f6e&#xff1a;<\/li>\n<p><span class=\"token key atrule\">routes<\/span><span class=\"token punctuation\">:<\/span><br \/>\n  <span class=\"token punctuation\">&#8211;<\/span> <span class=\"token key atrule\">id<\/span><span class=\"token punctuation\">:<\/span> user<span class=\"token punctuation\">&#8211;<\/span>service<br \/>\n    <span class=\"token key atrule\">uri<\/span><span class=\"token punctuation\">:<\/span> lb<span class=\"token punctuation\">:<\/span>\/\/user<span class=\"token punctuation\">&#8211;<\/span>service <span class=\"token comment\"># \u8d1f\u8f7d\u5747\u8861\u670d\u52a1\u540d<\/span><br \/>\n    <span class=\"token key atrule\">predicates<\/span><span class=\"token punctuation\">:<\/span><br \/>\n      <span class=\"token punctuation\">&#8211;<\/span> Path&#061;\/api\/user\/<span class=\"token important\">**<\/span><\/p>\n<h4>5.2 \u8d1f\u8f7d\u5747\u8861\u7b56\u7565\u914d\u7f6e<\/h4>\n<p>\u9ed8\u8ba4\u4f7f\u7528\u8f6e\u8be2\u7b56\u7565&#xff0c;\u53ef\u901a\u8fc7&#064;LoadBalancerClient\u6307\u5b9a\u5176\u4ed6\u7b56\u7565&#xff1a;<\/p>\n<p><span class=\"token annotation punctuation\">&#064;Configuration<\/span><br \/>\n<span class=\"token keyword\">public<\/span> <span class=\"token keyword\">class<\/span> <span class=\"token class-name\">LoadBalancerConfig<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token annotation punctuation\">&#064;Bean<\/span><br \/>\n    <span class=\"token keyword\">public<\/span> <span class=\"token class-name\">ReactorLoadBalancer<\/span><span class=\"token generics\"><span class=\"token punctuation\">&lt;<\/span><span class=\"token class-name\">ServiceInstance<\/span><span class=\"token punctuation\">&gt;<\/span><\/span> <span class=\"token function\">randomLoadBalancer<\/span><span class=\"token punctuation\">(<\/span><span class=\"token class-name\">Environment<\/span> environment<span class=\"token punctuation\">,<\/span><br \/>\n                                                                   <span class=\"token class-name\">ServiceInstanceListSupplier<\/span> supplier<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token keyword\">return<\/span> <span class=\"token keyword\">new<\/span> <span class=\"token class-name\">RandomLoadBalancer<\/span><span class=\"token punctuation\">(<\/span>environment<span class=\"token punctuation\">,<\/span> supplier<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span> <span class=\"token comment\">\/\/ \u968f\u673a\u7b56\u7565<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p><span class=\"token annotation punctuation\">&#064;LoadBalancerClient<\/span><span class=\"token punctuation\">(<\/span>name <span class=\"token operator\">&#061;<\/span> <span class=\"token string\">&#034;user-service&#034;<\/span><span class=\"token punctuation\">,<\/span> configuration <span class=\"token operator\">&#061;<\/span> <span class=\"token class-name\">LoadBalancerConfig<\/span><span class=\"token punctuation\">.<\/span><span class=\"token keyword\">class<\/span><span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token keyword\">public<\/span> <span class=\"token keyword\">interface<\/span> <span class=\"token class-name\">UserClient<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token comment\">\/\/ Feign\u5ba2\u6237\u7aef\u63a5\u53e3<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<h3>\u516d\u3001\u4e0eNacos\u7684\u52a8\u6001\u8def\u7531\u96c6\u6210<\/h3>\n<h4>6.1 \u52a8\u6001\u8def\u7531\u914d\u7f6e<\/h4>\n<li>\u5728Nacos\u63a7\u5236\u53f0\u521b\u5efa\u914d\u7f6e\u6587\u4ef6&#xff1a;<\/li>\n<p><span class=\"token comment\"># Data ID: gateway-routes.yaml<\/span><br \/>\n<span class=\"token key atrule\">spring<\/span><span class=\"token punctuation\">:<\/span><br \/>\n  <span class=\"token key atrule\">cloud<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token key atrule\">gateway<\/span><span class=\"token punctuation\">:<\/span><br \/>\n      <span class=\"token key atrule\">routes<\/span><span class=\"token punctuation\">:<\/span><br \/>\n        <span class=\"token punctuation\">&#8211;<\/span> <span class=\"token key atrule\">id<\/span><span class=\"token punctuation\">:<\/span> product<span class=\"token punctuation\">&#8211;<\/span>service<br \/>\n          <span class=\"token key atrule\">uri<\/span><span class=\"token punctuation\">:<\/span> lb<span class=\"token punctuation\">:<\/span>\/\/product<span class=\"token punctuation\">&#8211;<\/span>service<br \/>\n          <span class=\"token key atrule\">predicates<\/span><span class=\"token punctuation\">:<\/span><br \/>\n            <span class=\"token punctuation\">&#8211;<\/span> Path&#061;\/api\/product\/<span class=\"token important\">**<\/span><br \/>\n          <span class=\"token key atrule\">filters<\/span><span class=\"token punctuation\">:<\/span><br \/>\n            <span class=\"token punctuation\">&#8211;<\/span> StripPrefix&#061;1<\/p>\n<li>\u5728\u7f51\u5173\u670d\u52a1\u4e2d\u52a0\u8f7d\u914d\u7f6e&#xff1a;<\/li>\n<p><span class=\"token key atrule\">spring<\/span><span class=\"token punctuation\">:<\/span><br \/>\n  <span class=\"token key atrule\">cloud<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token key atrule\">config<\/span><span class=\"token punctuation\">:<\/span><br \/>\n      <span class=\"token key atrule\">import<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token string\">&#034;optional:nacos:gateway-routes.yaml&#034;<\/span><\/p>\n<li>\u52a8\u6001\u5237\u65b0\u8def\u7531&#xff1a;<\/li>\n<p><span class=\"token function\">curl<\/span> -X POST http:\/\/localhost:8080\/actuator\/gateway\/refresh<\/p>\n<h4>6.2 \u52a8\u6001\u670d\u52a1\u53d1\u73b0<\/h4>\n<p>\u7f51\u5173\u4f1a\u81ea\u52a8\u4eceNacos\u83b7\u53d6\u670d\u52a1\u5b9e\u4f8b\u5217\u8868&#xff0c;\u5b9e\u73b0\u52a8\u6001\u8d1f\u8f7d\u5747\u8861&#xff1a;<\/p>\n<p><span class=\"token key atrule\">uri<\/span><span class=\"token punctuation\">:<\/span> lb<span class=\"token punctuation\">:<\/span>\/\/product<span class=\"token punctuation\">&#8211;<\/span>service <span class=\"token comment\"># \u81ea\u52a8\u53d1\u73b0\u670d\u52a1\u5b9e\u4f8b<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb955\u6b21\uff0c\u70b9\u8d5e11\u6b21\uff0c\u6536\u85cf9\u6b21\u3002\u5728\u5fae\u670d\u52a1\u67b6\u6784\u4e2d\uff0cAPI \u7f51\u5173\u662f\u6d41\u91cf\u7684\u7edf\u4e00\u5165\u53e3\uff0c\u627f\u62c5\u7740\u8def\u7531\u8f6c\u53d1\u3001\u6d41\u91cf\u7ba1\u63a7\u3001\u5b89\u5168\u9632\u62a4\u7b49\u6838\u5fc3\u804c\u8d23\u3002Spring Cloud Gateway \u4f5c\u4e3a Spring \u5b98\u65b9\u63a8\u8350\u7684\u7b2c\u4e8c\u4ee3\u7f51\u5173\uff0c\u57fa\u4e8e Spring 5.0\u3001Spring Boot 2.0 \u548c Project Reactor \u6784\u5efa\uff0c\u63d0\u4f9b\u4e86\u9ad8\u6027\u80fd\u7684\u54cd\u5e94\u5f0f\u7f16\u7a0b\u6a21\u578b\u548c\u4e30\u5bcc\u7684\u6269\u5c55\u80fd\u529b\u3002\u672c\u6587\u5c06\u4ece\u57fa\u7840\u5165\u624b\uff0c\u6df1\u5165\u8bb2\u89e3\u8def\u7531\u3001\u65ad\u8a00\u3001\u8fc7\u6ee4\u5668\u3001\u8d1f\u8f7d\u5747\u8861\u53ca\u4e0e Nacos \u7684\u96c6\u6210\uff0c\u5e2e\u52a9\u8bfb\u8005\u5feb\u901f\u638c\u63e1 Gateway \u7684\u6838\u5fc3\u6280\u672f\u3002_springcloud gateway \u65ad\u8a00\u8def\u5f84\u5339\u914d\u6a21\u7cca\u5339\u914d\u53ef\u4ee5\u505a\u5305\u542b\u5173\u7cfb\u5417<\/p>\n","protected":false},"author":2,"featured_media":50713,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[1418,963,4950,668,4951],"topic":[],"class_list":["post-50714","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-gateway","tag-spring-cloud","tag-spring-cloud-gateway","tag-668","tag-4951"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u3010Spring Cloud Gateway \u5b9e\u6218\u7cfb\u5217\u3011\u57fa\u7840\u7bc7\uff1a\u8def\u7531\u3001\u65ad\u8a00\u3001\u8fc7\u6ee4\u5668\u3001\u8d1f\u8f7d\u5747\u8861\u6df1\u5ea6\u89e3\u6790 - \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\/50714.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u3010Spring Cloud Gateway \u5b9e\u6218\u7cfb\u5217\u3011\u57fa\u7840\u7bc7\uff1a\u8def\u7531\u3001\u65ad\u8a00\u3001\u8fc7\u6ee4\u5668\u3001\u8d1f\u8f7d\u5747\u8861\u6df1\u5ea6\u89e3\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb955\u6b21\uff0c\u70b9\u8d5e11\u6b21\uff0c\u6536\u85cf9\u6b21\u3002\u5728\u5fae\u670d\u52a1\u67b6\u6784\u4e2d\uff0cAPI \u7f51\u5173\u662f\u6d41\u91cf\u7684\u7edf\u4e00\u5165\u53e3\uff0c\u627f\u62c5\u7740\u8def\u7531\u8f6c\u53d1\u3001\u6d41\u91cf\u7ba1\u63a7\u3001\u5b89\u5168\u9632\u62a4\u7b49\u6838\u5fc3\u804c\u8d23\u3002Spring Cloud Gateway \u4f5c\u4e3a Spring \u5b98\u65b9\u63a8\u8350\u7684\u7b2c\u4e8c\u4ee3\u7f51\u5173\uff0c\u57fa\u4e8e Spring 5.0\u3001Spring Boot 2.0 \u548c Project Reactor \u6784\u5efa\uff0c\u63d0\u4f9b\u4e86\u9ad8\u6027\u80fd\u7684\u54cd\u5e94\u5f0f\u7f16\u7a0b\u6a21\u578b\u548c\u4e30\u5bcc\u7684\u6269\u5c55\u80fd\u529b\u3002\u672c\u6587\u5c06\u4ece\u57fa\u7840\u5165\u624b\uff0c\u6df1\u5165\u8bb2\u89e3\u8def\u7531\u3001\u65ad\u8a00\u3001\u8fc7\u6ee4\u5668\u3001\u8d1f\u8f7d\u5747\u8861\u53ca\u4e0e Nacos \u7684\u96c6\u6210\uff0c\u5e2e\u52a9\u8bfb\u8005\u5feb\u901f\u638c\u63e1 Gateway \u7684\u6838\u5fc3\u6280\u672f\u3002_springcloud gateway \u65ad\u8a00\u8def\u5f84\u5339\u914d\u6a21\u7cca\u5339\u914d\u53ef\u4ee5\u505a\u5305\u542b\u5173\u7cfb\u5417\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/50714.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-08-10T03:39:11+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/08\/20250810033909-6898145de3737.png\" \/>\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=\"3 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/50714.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/50714.html\",\"name\":\"\u3010Spring Cloud Gateway \u5b9e\u6218\u7cfb\u5217\u3011\u57fa\u7840\u7bc7\uff1a\u8def\u7531\u3001\u65ad\u8a00\u3001\u8fc7\u6ee4\u5668\u3001\u8d1f\u8f7d\u5747\u8861\u6df1\u5ea6\u89e3\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-08-10T03:39:11+00:00\",\"dateModified\":\"2025-08-10T03:39:11+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/50714.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/50714.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/50714.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u3010Spring Cloud Gateway \u5b9e\u6218\u7cfb\u5217\u3011\u57fa\u7840\u7bc7\uff1a\u8def\u7531\u3001\u65ad\u8a00\u3001\u8fc7\u6ee4\u5668\u3001\u8d1f\u8f7d\u5747\u8861\u6df1\u5ea6\u89e3\u6790\"}]},{\"@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":"\u3010Spring Cloud Gateway \u5b9e\u6218\u7cfb\u5217\u3011\u57fa\u7840\u7bc7\uff1a\u8def\u7531\u3001\u65ad\u8a00\u3001\u8fc7\u6ee4\u5668\u3001\u8d1f\u8f7d\u5747\u8861\u6df1\u5ea6\u89e3\u6790 - \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\/50714.html","og_locale":"zh_CN","og_type":"article","og_title":"\u3010Spring Cloud Gateway \u5b9e\u6218\u7cfb\u5217\u3011\u57fa\u7840\u7bc7\uff1a\u8def\u7531\u3001\u65ad\u8a00\u3001\u8fc7\u6ee4\u5668\u3001\u8d1f\u8f7d\u5747\u8861\u6df1\u5ea6\u89e3\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb955\u6b21\uff0c\u70b9\u8d5e11\u6b21\uff0c\u6536\u85cf9\u6b21\u3002\u5728\u5fae\u670d\u52a1\u67b6\u6784\u4e2d\uff0cAPI \u7f51\u5173\u662f\u6d41\u91cf\u7684\u7edf\u4e00\u5165\u53e3\uff0c\u627f\u62c5\u7740\u8def\u7531\u8f6c\u53d1\u3001\u6d41\u91cf\u7ba1\u63a7\u3001\u5b89\u5168\u9632\u62a4\u7b49\u6838\u5fc3\u804c\u8d23\u3002Spring Cloud Gateway \u4f5c\u4e3a Spring \u5b98\u65b9\u63a8\u8350\u7684\u7b2c\u4e8c\u4ee3\u7f51\u5173\uff0c\u57fa\u4e8e Spring 5.0\u3001Spring Boot 2.0 \u548c Project Reactor \u6784\u5efa\uff0c\u63d0\u4f9b\u4e86\u9ad8\u6027\u80fd\u7684\u54cd\u5e94\u5f0f\u7f16\u7a0b\u6a21\u578b\u548c\u4e30\u5bcc\u7684\u6269\u5c55\u80fd\u529b\u3002\u672c\u6587\u5c06\u4ece\u57fa\u7840\u5165\u624b\uff0c\u6df1\u5165\u8bb2\u89e3\u8def\u7531\u3001\u65ad\u8a00\u3001\u8fc7\u6ee4\u5668\u3001\u8d1f\u8f7d\u5747\u8861\u53ca\u4e0e Nacos \u7684\u96c6\u6210\uff0c\u5e2e\u52a9\u8bfb\u8005\u5feb\u901f\u638c\u63e1 Gateway \u7684\u6838\u5fc3\u6280\u672f\u3002_springcloud gateway \u65ad\u8a00\u8def\u5f84\u5339\u914d\u6a21\u7cca\u5339\u914d\u53ef\u4ee5\u505a\u5305\u542b\u5173\u7cfb\u5417","og_url":"https:\/\/www.wsisp.com\/helps\/50714.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-08-10T03:39:11+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/08\/20250810033909-6898145de3737.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"3 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/50714.html","url":"https:\/\/www.wsisp.com\/helps\/50714.html","name":"\u3010Spring Cloud Gateway \u5b9e\u6218\u7cfb\u5217\u3011\u57fa\u7840\u7bc7\uff1a\u8def\u7531\u3001\u65ad\u8a00\u3001\u8fc7\u6ee4\u5668\u3001\u8d1f\u8f7d\u5747\u8861\u6df1\u5ea6\u89e3\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-08-10T03:39:11+00:00","dateModified":"2025-08-10T03:39:11+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/50714.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/50714.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/50714.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u3010Spring Cloud Gateway \u5b9e\u6218\u7cfb\u5217\u3011\u57fa\u7840\u7bc7\uff1a\u8def\u7531\u3001\u65ad\u8a00\u3001\u8fc7\u6ee4\u5668\u3001\u8d1f\u8f7d\u5747\u8861\u6df1\u5ea6\u89e3\u6790"}]},{"@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\/50714","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=50714"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/50714\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/50713"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=50714"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=50714"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=50714"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=50714"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}