Skip to content

GH-3168: Document that @LoadBalanced RestClient must not be used in Gateway MVC#4200

Open
won-seoop wants to merge 1 commit into
spring-cloud:mainfrom
won-seoop:doc-3168-loadbalanced-restclient-warning
Open

GH-3168: Document that @LoadBalanced RestClient must not be used in Gateway MVC#4200
won-seoop wants to merge 1 commit into
spring-cloud:mainfrom
won-seoop:doc-3168-loadbalanced-restclient-warning

Conversation

@won-seoop

Copy link
Copy Markdown

Summary

Closes #3168

When a @LoadBalanced RestClient.Builder bean exists in the same application context as Spring Cloud Gateway Server MVC, Spring Cloud LoadBalancer intercepts the gateway's internal proxy RestClient requests before the lb() filter resolves the service instance — causing IllegalArgumentException: Service Instance cannot be null.

This was confirmed by @spencergibb in the issue: "Any RestClient bean used by Gateway MVC should NOT be @LoadBalanced as there is a separate lb() filter for that."

This PR adds a [[loadbalancer-restclient-warning]] section to loadbalancer.adoc that:

  • Explains the root cause: @LoadBalanced intercepts all outbound RestClient calls, including the gateway's internal proxy client
  • Shows the concrete error (Service Instance cannot be null)
  • Tells users to use the lb() filter or lb:// URI scheme for gateway routes, and reserve @LoadBalanced for beans their own code calls directly

Test plan

  • AsciiDoc renders without errors
  • The new section appears in the LoadBalancer Filter page

🤖 Generated with Claude Code

…sed with Gateway MVC

Document that a custom @LoadBalanced RestClient.Builder bean in the same
application context as the gateway will intercept the gateway's internal
proxy requests, causing an IllegalArgumentException: Service Instance
cannot be null before the lb() filter can resolve the target.

Users should rely only on the lb() filter or lb:// URI scheme for
load-balanced routing within the gateway; @LoadBalanced is for beans
that application code calls directly, not the gateway proxy client.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Gateway MVC: Service discovery with http prefix only works if RestClient.Builder is declared as a bean (which breaks lb:// routings)

2 participants