spring-bootspring-cloud

Call to service by the gateway is not found


I'm starting with spring cloud.

I created 3 application, one is for discovery service, one for gateway and one is a service. I'm not using actually spring cloud config and any load balacing

For my discovery

server.port=8761
spring.application.name=discovery-service
eureka.instance.hostname=localhost
eureka.client.registerWithEureka=false
eureka.client.fetchRegistry=false  
eureka.client.serviceUrl.defaultZone=http://${eureka.instance.hostname}:${server.port}/eureka/

For my gateway

#Port for Registry service
server.port=8080
spring.application.name=gateway-service
spring.cloud.gateway.discovery.locator.enabled=true
spring.cloud.gateway.routes[0].id=hostel-service
spring.cloud.gateway.routes[0].uri=lb://hostel-service
spring.cloud.gateway.routes[0].predicates[0]=Path=/hostels/**
eureka.client.serviceUrl.defaultZone=http://localhost:8761/eureka/

For my hostels service

server.port=9000
spring.application.name=hostel-service
eureka.client.serviceUrl.defaultZone=http://localhost:8761/eureka/

I see then hostel service is registered in the discovery service

Registered instance HOSTEL-SERVICE/192.168.102.129:hostel-service:9000 with status UP (replication=false)

See it to when i go to http://localhost:8761/

When I try to call

http://localhost:8080/hostels or http://localhost:8080/hostel-service/hostels

I get a 404 error

If I do

http://localhost:9000/hostels

I get good results

Edit

Code on github

https://github.com/mctdi/hostel
https://github.com/mctdi/gateway
https://github.com/mctdi/discovery


Solution

  • The hostels app registers in Service Discovery, but the gateway app doesn't. Add 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client' to you implementation dependencies in build.gradle - it will then register in Eureka and the http://localhost:8080/hostels request will be routed to the hostels app.