Replace Zuul routes with Spring Cloud Gateway configuration#30
Replace Zuul routes with Spring Cloud Gateway configuration#3098001yash wants to merge 2 commits intospring-petclinic:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR migrates the API Gateway configuration from the deprecated Zuul to Spring Cloud Gateway, replacing legacy routing configuration with modern reactive routing. The change is necessary to enable compatibility with Spring Cloud Gateway, the reactive WebFlux stack, and OAuth2 Resource Server (JWT) authentication.
Changes:
- Removed legacy Zuul routing configuration (prefix-based routing)
- Added Spring Cloud Gateway route definitions for customers-service, vets-service, and visits-service using load-balanced URIs
- Configured path-based predicates and StripPrefix filters for each route
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| - StripPrefix=2 | ||
|
|
||
| - id: vets-service | ||
| uri: lb://vets-service | ||
| predicates: | ||
| - Path=/api/vets/** | ||
| filters: | ||
| - StripPrefix=2 | ||
|
|
||
| - id: visits-service | ||
| uri: lb://visits-service | ||
| predicates: | ||
| - Path=/api/visits/** | ||
| filters: | ||
| - StripPrefix=2 |
There was a problem hiding this comment.
The StripPrefix value appears incorrect. With StripPrefix=2, a request to /api/vets/123 would strip both /api and /vets, forwarding only /123 to the vets-service.
The legacy Zuul configuration only stripped the /api prefix, forwarding requests like /vet/123 to the service. To maintain equivalent behavior, this should be StripPrefix=1 to only strip the /api segment.
If the service endpoints have changed to expect paths without the service name prefix (which would be unusual), then StripPrefix=2 is correct, but this would represent a breaking API change that should be documented.
| - StripPrefix=2 | |
| - id: vets-service | |
| uri: lb://vets-service | |
| predicates: | |
| - Path=/api/vets/** | |
| filters: | |
| - StripPrefix=2 | |
| - id: visits-service | |
| uri: lb://visits-service | |
| predicates: | |
| - Path=/api/visits/** | |
| filters: | |
| - StripPrefix=2 | |
| - StripPrefix=1 | |
| - id: vets-service | |
| uri: lb://vets-service | |
| predicates: | |
| - Path=/api/vets/** | |
| filters: | |
| - StripPrefix=1 | |
| - id: visits-service | |
| uri: lb://visits-service | |
| predicates: | |
| - Path=/api/visits/** | |
| filters: | |
| - StripPrefix=1 |
api-gateway.yml
Outdated
| - id: customers-service | ||
| uri: lb://customers-service | ||
| predicates: | ||
| - Path=/api/customers/** |
There was a problem hiding this comment.
The path pattern has been changed from /api/customer/** (singular) in the Zuul configuration to /api/customers/** (plural). This is a breaking API change that will cause existing API clients using the /api/customer/** endpoints to receive 404 errors.
If this path change is intentional to align with RESTful naming conventions, it should be clearly documented in the PR description as a breaking change. Otherwise, the path should remain /api/customer/** for backward compatibility.
| - Path=/api/customers/** | |
| - Path=/api/customer/** |
api-gateway.yml
Outdated
| - id: vets-service | ||
| uri: lb://vets-service | ||
| predicates: | ||
| - Path=/api/vets/** |
There was a problem hiding this comment.
The path pattern has been changed from /api/vet/** (singular) in the Zuul configuration to /api/vets/** (plural). This is a breaking API change that will cause existing API clients using the /api/vet/** endpoints to receive 404 errors.
If this path change is intentional to align with RESTful naming conventions, it should be clearly documented in the PR description as a breaking change. Otherwise, the path should remain /api/vet/** for backward compatibility.
| - Path=/api/vets/** | |
| - Path=/api/vet/** |
|
The branch has been updated and the diff should now be visible. |
|
Hi @98001yash we could remove all zuul routes from the |
Summary
This PR replaces the legacy Zuul-based routing configuration with Spring Cloud Gateway routes in
api-gateway.yml.The main
spring-petclinic-microservicesproject uses Spring Cloud Gateway as the API Gateway.However, the config repository still contained Zuul configuration, which is deprecated and incompatible with:
This mismatch caused routes like
/api/**to return 404 even though services were registered in Eureka.Changes
lb://Result
/api/customers/**are routed successfullyNotes
This change is a prerequisite for implementing OAuth2 security using Spring Security and Keycloak.