Skip to content

Replace Zuul routes with Spring Cloud Gateway configuration#30

Closed
98001yash wants to merge 2 commits intospring-petclinic:mainfrom
98001yash:patch-1
Closed

Replace Zuul routes with Spring Cloud Gateway configuration#30
98001yash wants to merge 2 commits intospring-petclinic:mainfrom
98001yash:patch-1

Conversation

@98001yash
Copy link
Copy Markdown

Summary
This PR replaces the legacy Zuul-based routing configuration with Spring Cloud Gateway routes in api-gateway.yml.

The main spring-petclinic-microservices project uses Spring Cloud Gateway as the API Gateway.
However, the config repository still contained Zuul configuration, which is deprecated and incompatible with:

  • Spring Cloud Gateway
  • Reactive stack (WebFlux)
  • OAuth2 Resource Server (JWT)

This mismatch caused routes like /api/** to return 404 even though services were registered in Eureka.

Changes

  • Removed all Zuul configuration
  • Added Spring Cloud Gateway routes for:
    • customers-service
    • vets-service
    • visits-service
  • Enabled service discovery–based routing using lb://

Result

  • Gateway routes are correctly loaded
  • Requests like /api/customers/** are routed successfully
  • Enables proper OAuth2/JWT authentication at the gateway layer

Notes

This change is a prerequisite for implementing OAuth2 security using Spring Security and Keycloak.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +10 to +24
- 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
Copy link

Copilot AI Jan 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
- 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

Copilot uses AI. Check for mistakes.
api-gateway.yml Outdated
- id: customers-service
uri: lb://customers-service
predicates:
- Path=/api/customers/**
Copy link

Copilot AI Jan 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
- Path=/api/customers/**
- Path=/api/customer/**

Copilot uses AI. Check for mistakes.
api-gateway.yml Outdated
- id: vets-service
uri: lb://vets-service
predicates:
- Path=/api/vets/**
Copy link

Copilot AI Jan 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
- Path=/api/vets/**
- Path=/api/vet/**

Copilot uses AI. Check for mistakes.
@98001yash
Copy link
Copy Markdown
Author

The branch has been updated and the diff should now be visible.
Please let me know if any further changes are required.

@98001yash 98001yash closed this Jan 24, 2026
@98001yash 98001yash reopened this Jan 24, 2026
@arey
Copy link
Copy Markdown
Member

arey commented Jan 29, 2026

Hi @98001yash we could remove all zuul routes from the api-gateway.yml. The application.yml of the spring-petclinic-api-gateway microservices already declared Spring Cloud Gateway routes. See https://github.com/spring-petclinic/spring-petclinic-microservices/blob/main/spring-petclinic-api-gateway/src/main/resources/application.yml
I've just prepared the Merge Request: #31

@arey arey closed this Jan 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants