[Spring Cloud Gateway MVC]DefaultFunctionConfiguration automatically intercepts 1 and 2-segment local @RestController endpoints due to matchIfMissing=true
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 初心者へのやさしさ
- 65/100
- issue の種類
- バグ
- 明瞭さ
- おおむね明確
- 活発さ
- 静か
- 技術スタック
- java, spring, spring-boot
調査の方向性
まず DefaultFunctionConfiguration.java を読み、特に @ConditionalOnProperty 宣言と、32-41 行目に記載されている gatewayToFunctionRouter のルートを確認します。次に、RouterFunctionMapping がこれらのルートをローカルのコントローラーマッピングに対してどのような順序で処理するかを確認します。1 セグメントおよび 2 セグメントのエンドポイントケースを再現し、完了した変更によってローカルの @RestController パスが引き続き到達可能であり、意図した関数ルーティングの動作が維持されることを検証します。
索引モデルが issue の本文から書いたものです。
説明
Bug Description
In Spring Cloud Gateway Server WebMVC, DefaultFunctionConfiguration is auto-configured with a default property match condition of matchIfMissing = true on spring.cloud.gateway.mvc.function.enabled.
Because Spring Framework 6.1+ changed the execution order of RouterFunctionMapping to -1 (via WebMvcConfigurationSupport), the un-prefixed, greedy path patterns /{path} and /{path}/{name} registered inside DefaultFunctionConfiguration take unconditional priority over standard user-defined @RestController paths.
As a result, any local controller with 1 or 2 segments (e.g., GET /items, POST /users/action) is entirely hijacked and handled by the gateway's functionroute router mapping loop, causing downstream target exceptions or context errors. Conversely, local endpoints with 3 or more segments (e.g., /api/v1/resource) successfully drop down to RequestMappingHandlerMapping because no 3+ segment pattern is declared in the default function routes.
This default-on behavior creates a highly destructive side effect for teams attempting to run hybrid microservices (local controller code executing inside the Gateway JVM).
Steps to Reproduce
- Create a Spring Cloud Gateway MVC application including
spring-cloud-function-contextor a similar classpath trigger. - Maintain default configuration values (do not explicitly set
spring.cloud.gateway.mvc.function.enabled). - Implement a local
@RestControllerendpoint mapped to a 2-segment path:@PostMapping("/path/action") public ResponseEntity<String> localAction() { return ResponseEntity.ok("Success"); } - Send a
POSTrequest to/path/action. - Observed Behavior: The request is captured by
RouterFunctionMapping(viafunctionroute), bypasses the local@RestController, and fails or gets routed contextually intoHandlerFunctions.fn().
Root Cause Isolation
The issue stems directly from lines 32-41 of DefaultFunctionConfiguration.java:
@Configuration
@ConditionalOnClass(name = "org.springframework.cloud.function.context.FunctionCatalog")
@ConditionalOnProperty(name = GatewayMvcProperties.PREFIX + ".function.enabled", havingValue = "true",
matchIfMissing = true) // <-- ANTI-PATTERN DEFAULT
public class DefaultFunctionConfiguration {
@Bean
RouterFunction<ServerResponse> gatewayToFunctionRouter() {
return route("functionroute")
.POST("/{path}/{name}", fn("{path}/{name}")) // Overrides 2-segment controller paths
.POST("/{path}", fn("{path}")) // Overrides 1-segment controller paths
.GET("/{path}/{name}", fn("{path}/{name}"))
.GET("/{path}", fn("{path}"))
.build();
}
}
Because matchIfMissing = true is declared on global naked wildcards at a framework priority order of -1, it acts as a trap for any developer endpoint that is shorter than 3 segments deep.
Proposed Changes / Fixes
- Change default fallback logic: Change
matchIfMissing = truetomatchIfMissing = false. Function routing integration should be an explicit opt-in feature rather than breaking standard Spring MVC route resolution patterns by default. - Namespace the routing paths: If the bean must persist by default, the paths should be namespaced (e.g.,
/functions/{path}and/functions/{path}/{name}) to protect root-level tenant namespace allocations on local applications.
- 主要言語
- Java
- スター
- 4.9k
- フォーク
- 3.5k
- 平均マージ
- 1日 13時間
- マージ済み PR(30日)
- 14
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
spring-cloud/spring-cloud-gateway のほかの issue
-
waiting-for-triage
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
spring-cloud/spring-cloud-gateway#4395 ·
メンテナーはふだん 1 日以内に返信
-
RequestRateLimiterGatewayFilterFactory commits 429 response instead of throwing対応中かも @seonwooj0810 が 175 日前に担当しました。 オープンwaiting-for-triage
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
spring-cloud/spring-cloud-gateway#4175 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
Add @Order annotation to gatewayRestClientCustomizer Bean対応中かも @CheHyeonYeong が 247 日前に担当しました。 オープンenhancement help wanted
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
spring-cloud/spring-cloud-gateway#3626 · コメント 3 件 ·
メンテナーはふだん 1 日以内に返信
-
Ambiguity in section 19 of the documentation - Spring Cloud Gateway - Custom Route Predicate対応中かも @won-seoop が 173 日前に担当しました。 オープンdocumentation
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
spring-cloud/spring-cloud-gateway#3463 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
waiting for feedback
難易度 4/5 3〜5日 初心者へのやさしさ 48/100
spring-cloud/spring-cloud-gateway#4394 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
spring-cloud/spring-cloud-gateway の issue をすべて見る
似ている issue
-
area:cpan-port area:performance bug
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
fglock/PerlOnJava#2230 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
federicoiosue/Omni-Notes#1044 ·
-
Bug
難易度 1/5 1時間未満 初心者へのやさしさ 68/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
メンテナーはふだん 1 日以内に返信