I am developing a simple microservices application using Spring Cloud Gateway along with Keycloak.
I have two services, which are behind the API Gateway:
- Product Service
- Order Service
- Inventory Service
When I try to access the Product Service URL (/api/product - GET Request) through browser, I am redirected to Keycloak Authentication Page and after authentication, I am seeing the required output.
But when I try to access it through POSTMAN, the very first request I make is returning a 404 response like below, and the following requests are working fine. I get the below response for the first request:
{
"timestamp": "2021-02-23T22:36:19.590+00:00",
"path": "/",
"status": 404,
"error": "Not Found",
"message": null,
"requestId": "6509ccde-6"
}
The API Gateway is properly registered with the Eureka Server.
Here is my API Gateway application.properties file:
spring.application.name=api-gateway
spring.cloud.gateway.discovery.locator.enabled=true
spring.cloud.gateway.discovery.locator.lower-case-service-id=true
spring.cloud.loadbalancer.ribbon.enabled=false
spring.cloud.gateway.default-filters=TokenRelay
spring.cloud.gateway.routes[0].id=product-service
spring.cloud.gateway.routes[0].uri=lb://product-service
spring.cloud.gateway.routes[0].predicates[0]=Path=/api/product
spring.cloud.gateway.routes[1].id=order-service
spring.cloud.gateway.routes[1].uri=lb://order-service
spring.cloud.gateway.routes[1].predicates[0]=Path=/api/order
eureka.instance.instance-id=${spring.application.name}-${random.uuid}
spring.security.oauth2.client.provider.keycloak.issuer-uri=http://localhost:8180/auth/realms/microservices-realm
spring.security.oauth2.client.registration.spring-cloud-gateway-client.client-id=spring-cloud-gateway-client
spring.security.oauth2.client.registration.spring-cloud-gateway-client.client-secret=secret
spring.security.oauth2.client.registration.spring-cloud-gateway-client.provider=keycloak
spring.security.oauth2.client.registration.spring-cloud-gateway-client.authorization-grant-type=authorization_code
spring.security.oauth2.client.registration.spring-cloud-gateway-client.redirect-uri=http://localhost:8080/login/oauth2/code/spring-cloud-gateway-client
I am receiving the same error also when accessing the order service (/api/order - POST)
Some Extra Info:
Order Service is communicating with Inventory Service, through Feign Client, when I make the /api/order POST call.
I am using Spring Boot Version - 2.3.8.RELEASE and Spring Cloud Version - Hoxton.SR10
Can anyone point out what I am doing wrong here?