{"id":3441,"date":"2025-12-24T10:01:27","date_gmt":"2025-12-24T15:01:27","guid":{"rendered":"https:\/\/www.mymiller.name\/wordpress\/?p=3441"},"modified":"2025-12-24T10:01:27","modified_gmt":"2025-12-24T15:01:27","slug":"spring-cloud-gateway-with-spring-cloud-discovery","status":"publish","type":"post","link":"https:\/\/www.mymiller.name\/wordpress\/spring_discovery\/spring-cloud-gateway-with-spring-cloud-discovery\/","title":{"rendered":"Spring Cloud Gateway with Spring Cloud Discovery"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Spring Cloud Gateway and Spring Cloud Discovery are powerful tools for building microservices architectures. Spring Cloud Gateway acts as an API gateway, routing requests to the appropriate microservices. Spring Cloud Discovery provides a registry for microservices, enabling dynamic service discovery and load balancing.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In this comprehensive guide, we&#8217;ll delve into the integration of Spring Cloud Gateway with Spring Cloud Discovery using Spring 3.1.x and the latest version of Spring Cloud, empowering you to build resilient and scalable microservices architectures.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Prerequisites<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Before embarking on this journey, ensure you have the following prerequisites in place:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Java Development Kit (JDK) 11 or higher<\/li>\n\n\n\n<li>Maven or Gradle<\/li>\n\n\n\n<li>Spring Boot 2.7.0 or higher<\/li>\n\n\n\n<li>Spring Cloud Dependency Management (BOM)<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Maven Dependencies<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For Maven-based projects, include the following dependencies in your pom.xml file:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;dependency&gt;\n    &lt;groupId&gt;org.springframework.cloud&lt;\/groupId&gt;\n    &lt;artifactId&gt;spring-cloud-starter-gateway&lt;\/artifactId&gt;\n&lt;\/dependency&gt;\n&lt;dependency&gt;\n    &lt;groupId&gt;org.springframework.cloud&lt;\/groupId&gt;\n    &lt;artifactId&gt;spring-cloud-starter-netflix-eureka-client&lt;\/artifactId&gt;\n&lt;\/dependency&gt;\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Gradle Dependencies<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For Gradle-based projects, include the following dependencies in your build.gradle file:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>dependencies {\n    implementation \"org.springframework.cloud:spring-cloud-starter-gateway\"\n    implementation \"org.springframework.cloud:spring-cloud-starter-netflix-eureka-client\"\n}\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Configuration Settings<\/strong><\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Application.yml:<\/strong><\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>spring:\n  cloud:\n    gateway:\n      discovery:\n        locator:\n          enabled: true\n<\/code><\/pre>\n\n\n\n<ol class=\"wp-block-list\" start=\"2\">\n<li><strong>bootstrap.yml:<\/strong><\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>spring:\n  cloud:\n    eureka:\n      client:\n        register-with-eureka: true\n        fetch-registry: true\n        service-url:\n          defaultZone: http:\/\/localhost:8761\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Dynamic Routes<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Spring Cloud Gateway enables dynamic route discovery using Spring Cloud Discovery. This feature allows the gateway to automatically discover and configure routes based on the registered microservices in the registry.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Route Configuration:<\/strong><\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>routes:\n  - id: kitchen-route\n    uri: lb:\/\/kitchen\n    predicates:\n      - Path=\/kitchen\/**\n  - id: tracker-route\n    uri: lb:\/\/tracker\n    predicates:\n      - Path=\/tracker\/**\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">In this example, the gateway will automatically discover microservices named <code>kitchen<\/code> and <code>tracker<\/code> and create routes accordingly. The <code>lb:<\/code> prefix in the <code>uri<\/code> indicates load balancing across available instances of the microservice.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Dynamic Routes with Custom Locator<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For more granular control over route discovery, you can implement a custom <code>DiscoveryClientRouteDefinitionLocator<\/code>. This class provides the flexibility to define routes based on custom criteria and logic.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Benefits of Spring Cloud Gateway with Spring Cloud Discovery<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Dynamic Routing:<\/strong> Automatically discover and configure routes based on registered microservices.<\/li>\n\n\n\n<li><strong>Load Balancing:<\/strong> Distribute traffic across multiple instances of microservices for optimal performance and availability.<\/li>\n\n\n\n<li><strong>Service Discovery:<\/strong> Eliminate the need for manual configuration of service URLs and endpoints.<\/li>\n\n\n\n<li><strong>Centralized Management:<\/strong> Monitor and manage microservices from a single pane of glass.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Conclusion<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Spring Cloud Gateway and Spring Cloud Discovery empower developers to build resilient and scalable microservices architectures with ease. By leveraging dynamic routes and centralized service discovery, you can simplify deployment and management, ensuring your microservices remain agile and responsive to changing demands.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Spring Cloud Gateway and Spring Cloud Discovery are powerful tools for building microservices architectures. Spring Cloud Gateway acts as an API gateway, routing requests to the appropriate microservices. Spring Cloud Discovery provides a registry for microservices, enabling dynamic service discovery and load balancing. In this comprehensive guide, we&#8217;ll delve into the integration of Spring Cloud [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":3442,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_coblocks_attr":"","_coblocks_dimensions":"","_coblocks_responsive_height":"","_coblocks_accordion_ie_support":"","_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[432],"tags":[319],"series":[397],"class_list":["post-3441","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-spring_discovery","tag-spring","series-spring"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2023\/11\/trees-2900064_640.jpg?fit=640%2C427&ssl=1","jetpack-related-posts":[{"id":3438,"url":"https:\/\/www.mymiller.name\/wordpress\/spring\/architecting-with-spring-and-spring-cloud\/","url_meta":{"origin":3441,"position":0},"title":"Architecting with Spring and Spring Cloud","author":"Jeffery Miller","date":"December 24, 2025","format":false,"excerpt":"Building a Multi-Service Architecture with Spring 3.1.x and Spring Cloud: Unlocking the Power of Microservices In the ever-evolving landscape of software development, microservices have emerged as a powerful architectural paradigm, enabling organizations to build scalable, resilient, and agile applications. Spring, a widely adopted Java framework, provides a comprehensive suite of\u2026","rel":"","context":"In &quot;Spring&quot;","block_context":{"text":"Spring","link":"https:\/\/www.mymiller.name\/wordpress\/category\/spring\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2023\/11\/field-5236879_640.jpg?fit=640%2C360&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2023\/11\/field-5236879_640.jpg?fit=640%2C360&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2023\/11\/field-5236879_640.jpg?fit=640%2C360&ssl=1&resize=525%2C300 1.5x"},"classes":[]},{"id":3828,"url":"https:\/\/www.mymiller.name\/wordpress\/spring-gateway\/load-balancing-your-microservices-configuring-spring-cloud-gateway-with-spring-discovery-server\/","url_meta":{"origin":3441,"position":1},"title":"Load Balancing Your Microservices: Configuring Spring Cloud Gateway with Spring Discovery Server","author":"Jeffery Miller","date":"December 24, 2025","format":false,"excerpt":"In a microservices architecture, ensuring high availability and distributing traffic evenly across multiple instances of a service is paramount. Spring Cloud Gateway, when integrated with a Spring Discovery Server (like Netflix Eureka, Consul, or Spring Cloud Service Registry), provides a powerful and straightforward way to achieve client-side load balancing without\u2026","rel":"","context":"In &quot;Spring Gateway&quot;","block_context":{"text":"Spring Gateway","link":"https:\/\/www.mymiller.name\/wordpress\/category\/spring-gateway\/"},"img":{"alt_text":"","src":"https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2025\/04\/meditation-3814069_1280.avif","width":350,"height":200,"srcset":"https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2025\/04\/meditation-3814069_1280.avif 1x, https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2025\/04\/meditation-3814069_1280.avif 1.5x, https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2025\/04\/meditation-3814069_1280.avif 2x, https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2025\/04\/meditation-3814069_1280.avif 3x"},"classes":[]},{"id":3721,"url":"https:\/\/www.mymiller.name\/wordpress\/spring_discovery\/load-balancing-in-spring-gateway-discovery\/","url_meta":{"origin":3441,"position":2},"title":"Load Balancing in Spring: Gateway &amp; Discovery","author":"Jeffery Miller","date":"April 20, 2026","format":false,"excerpt":"Load balancing is crucial in modern applications to distribute traffic across multiple instances of a service, ensuring high availability and fault tolerance. Spring provides robust mechanisms for load balancing, both at the gateway level and through service discovery. This blog post will explore both approaches, highlighting their differences and use\u2026","rel":"","context":"In &quot;Spring Discovery&quot;","block_context":{"text":"Spring Discovery","link":"https:\/\/www.mymiller.name\/wordpress\/category\/spring_discovery\/"},"img":{"alt_text":"","src":"https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/09\/network-8198745_1280-jpg.avif","width":350,"height":200,"srcset":"https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/09\/network-8198745_1280-jpg.avif 1x, https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/09\/network-8198745_1280-jpg.avif 1.5x, https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/09\/network-8198745_1280-jpg.avif 2x, https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/09\/network-8198745_1280-jpg.avif 3x"},"classes":[]},{"id":3444,"url":"https:\/\/www.mymiller.name\/wordpress\/spring_discovery\/spring-boot-admin-server-with-spring-cloud-discovery\/","url_meta":{"origin":3441,"position":3},"title":"Spring Boot Admin Server with Spring Cloud Discovery","author":"Jeffery Miller","date":"December 24, 2025","format":false,"excerpt":"Spring Boot Admin Server is a powerful tool for monitoring and managing Spring Boot applications. It provides a centralized dashboard for viewing application health, metrics, and logs. Spring Cloud Discovery, on the other hand, enables service registration and discovery for microservices-based applications. By integrating Spring Boot Admin Server with Spring\u2026","rel":"","context":"In &quot;Spring Discovery&quot;","block_context":{"text":"Spring Discovery","link":"https:\/\/www.mymiller.name\/wordpress\/category\/spring_discovery\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2023\/11\/manhattan-3866140_640.jpg?fit=640%2C427&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2023\/11\/manhattan-3866140_640.jpg?fit=640%2C427&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2023\/11\/manhattan-3866140_640.jpg?fit=640%2C427&ssl=1&resize=525%2C300 1.5x"},"classes":[]},{"id":3647,"url":"https:\/\/www.mymiller.name\/wordpress\/spring\/centralized-api-documentation-with-spring-gateway-and-springdoc\/","url_meta":{"origin":3441,"position":4},"title":"Centralized API Documentation with Spring Gateway and Springdoc","author":"Jeffery Miller","date":"December 24, 2025","format":false,"excerpt":"In microservices architectures, where multiple services expose their own APIs, having centralized documentation is crucial for developers and consumers. Spring Gateway, acting as the API gateway, can be leveraged to aggregate and present documentation from various services in a unified manner using Springdoc. Let\u2019s explore how to achieve this. Prerequisites\u2026","rel":"","context":"In &quot;Spring&quot;","block_context":{"text":"Spring","link":"https:\/\/www.mymiller.name\/wordpress\/category\/spring\/"},"img":{"alt_text":"","src":"https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/08\/library-488683_1280-jpg.avif","width":350,"height":200,"srcset":"https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/08\/library-488683_1280-jpg.avif 1x, https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/08\/library-488683_1280-jpg.avif 1.5x, https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/08\/library-488683_1280-jpg.avif 2x, https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/08\/library-488683_1280-jpg.avif 3x"},"classes":[]},{"id":3830,"url":"https:\/\/www.mymiller.name\/wordpress\/spring-gateway\/scaling-the-gatekeeper-load-balancing-multiple-instances-of-spring-cloud-gateway\/","url_meta":{"origin":3441,"position":5},"title":"Scaling the Gatekeeper: Load Balancing Multiple Instances of Spring Cloud Gateway","author":"Jeffery Miller","date":"December 24, 2025","format":false,"excerpt":"As your microservices ecosystem grows and traffic increases, a single instance of Spring Cloud Gateway might become a bottleneck or a single point of failure. To ensure high availability, fault tolerance, and improved performance, you\u2019ll likely need to run multiple instances of your Spring Cloud Gateway and load balance traffic\u2026","rel":"","context":"In &quot;Spring Gateway&quot;","block_context":{"text":"Spring Gateway","link":"https:\/\/www.mymiller.name\/wordpress\/category\/spring-gateway\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2023\/11\/network-3152677_640.jpg?fit=640%2C427&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2023\/11\/network-3152677_640.jpg?fit=640%2C427&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2023\/11\/network-3152677_640.jpg?fit=640%2C427&ssl=1&resize=525%2C300 1.5x"},"classes":[]}],"jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/posts\/3441","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/comments?post=3441"}],"version-history":[{"count":1,"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/posts\/3441\/revisions"}],"predecessor-version":[{"id":3443,"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/posts\/3441\/revisions\/3443"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/media\/3442"}],"wp:attachment":[{"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/media?parent=3441"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/categories?post=3441"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/tags?post=3441"},{"taxonomy":"series","embeddable":true,"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/series?post=3441"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}