lb:// URIとDiscovery Locator
Spring Cloud Gatewayがサービスディスカバリを通じてlb://スキームを解決する仕組みと、登録済みサービスからルートを自動作成する方法を理解します。
「lb:// URIとDiscovery Locator」はCoddyKit上の無料API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway)レッスンです。 これはレッスン4/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはAPI Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway)学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway)コースには全4レッスンが含まれています。
このレッスンの一部はまだ翻訳されておらず、英語で表示されています。
From Hostnames to Service Names
Hardcoding http://10.0.0.5:8080 breaks when instances move. With service discovery the gateway can target a logical service name instead, and resolve real instances at runtime.
The lb Scheme
Prefix a route's uri with lb:// followed by the service id. The gateway hands the request to the load balancer, which picks a live instance.
routes:
- id: orders
uri: lb://order-service
predicates:
- Path=/orders/**How lb Is Resolved
At request time the gateway asks the discovery client (Eureka, Consul, etc.) for instances of order-service, then Spring Cloud LoadBalancer selects one. The lb:// host is replaced by a concrete address.
Required Dependencies
You need a discovery client and the load balancer on the classpath. With Eureka:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>The Discovery Locator
Instead of writing a route per service, enable the DiscoveryClient route locator. It auto-generates a route for every registered service.
spring:
cloud:
gateway:
discovery:
locator:
enabled: trueAuto-Generated Paths
By default each service is reachable at /SERVICE-ID/**. A service named order-service answers at /order-service/**, forwarded as lb://order-service.
# request /order-service/orders/42
# -> lb://order-service /orders/42Lowercasing Service IDs
Eureka often registers service ids in uppercase. Enable lowercasing so paths stay clean and predictable.
spring:
cloud:
gateway:
discovery:
locator:
lower-case-service-id: trueMixing Manual and Auto Routes
You can keep the discovery locator on for convenience while still defining explicit routes for services that need custom predicates or filters.
routes:
- id: orders-custom
uri: lb://order-service
predicates:
- Path=/api/orders/**
filters:
- StripPrefix=1When Auto Routes Are Risky
The locator exposes every service automatically, including internal ones. In production, many teams disable it and define routes explicitly for tighter control.
Health-Aware Selection
Because resolution happens per request, instances that deregister or fail health checks are dropped from the pool. New instances appear automatically as they register.
Verifying Resolution
Enable debug logging for the load balancer to see which instance each request was routed to.
logging:
level:
org.springframework.cloud.loadbalancer: DEBUGQuick Check
What does the lb:// prefix on a route's URI tell the gateway to do?
Recap
You connected the gateway to service discovery:
lb://service-idresolves instances dynamically- A discovery client and load balancer must be present
- The discovery locator auto-creates routes at
/service-id/** - Disable or scope it in production for safety
This is the backbone of dynamic, resilient routing.
AI チューターと学ぶ API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) — 無料
ブラウザでリアルコードを書いて実行し、24/7 の AI チューターから瞬時にサポートを受け、ウェブまたはアプリで続きから学習できます。
- コース
- 12
- レッスン
- 48
よくある質問
「lb:// URIとDiscovery Locator」レッスンは無料ですか?
はい。「lb:// URIとDiscovery Locator」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway)コースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway)コースには全4レッスンが含まれています。
「lb:// URIとDiscovery Locator」で何を学びますか?
Spring Cloud Gatewayがサービスディスカバリを通じてlb://スキームを解決する仕組みと、登録済みサービスからルートを自動作成する方法を理解します。 ブラウザで直接実行するハンズオンコードでAPI Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway)を演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。
API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway)を始めるのに経験は必要ですか?
事前経験は必要ありません。CoddyKitのAPI Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway)は初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン4/4です。
「lb:// URIとDiscovery Locator」レッスンにはどのくらい時間がかかりますか?
ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。
このAPI Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway)レッスンでコードを書いて実行できますか?
はい。すべてのAPI Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway)レッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。
このコースのすべてのレッスン
- Eureka/Consulとの統合
- サービスディスカバリによる動的ルーティング
- Spring Cloud LoadBalancerによるロードバランシング
- lb:// URIとDiscovery Locator