Routing is not working - Spring cloud gateway + Eureka Server

See original GitHub issue
@SpringBootApplication
@EnableEurekaClient
@Configuration
public class GatewayApplication {

    @Bean
    public RouteLocator customRouteLocator(RouteLocatorBuilder builder) {
        return builder.routes()
                .route("um_route", r -> r
                        .path("/um/**")
                        .uri("lb://user-management")
                )
                .build();
    }
}

discovery.locator is enabled as:

spring.application.name=gateway
server.port=10002

spring.cloud.gateway.discovery.locator.enabled=true
spring.cloud.gateway.discovery.locator.lower-case-service-id=true

application is registed: 2018-08-20 15 50 51

but when I http://localhost:10002/um/hello I got 404 as response

ps: it seems spring cloud gateway have a default config for the routing as /application-name/ so I got response by url http://localhost:10002/user-management/hello But still don’t know how to customize the routing url

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

6reactions
poppinlrcommented, Sep 18, 2018

.filters(f -> f.stripPrefix(1))

Sorry for spelling mistake, I think .filters(f -> f.stripPrefix(1)) help to solve the problem, thanks!

2reactions
adnanmamajiwalacommented, Sep 6, 2018

@ryanjbaxter I am facing a similar problem, the loadbalancer is not able to retrieve the server list.

Error message:

2018-09-05 23:20:17.751  INFO 47037 --- [ctor-http-nio-2] c.netflix.loadbalancer.BaseLoadBalancer  : Client: localhost instantiated a LoadBalancer: DynamicServerListLoadBalancer:{NFLoadBalancer:name=localhost,current list of Servers=[],Load balancer stats=Zone stats: {},Server stats: []}ServerList:null
2018-09-05 23:20:17.756  INFO 47037 --- [ctor-http-nio-2] c.n.l.DynamicServerListLoadBalancer      : Using serverListUpdater PollingServerListUpdater
2018-09-05 23:20:17.760  INFO 47037 --- [ctor-http-nio-2] c.n.l.DynamicServerListLoadBalancer      : DynamicServerListLoadBalancer for client localhost initialized: DynamicServerListLoadBalancer:{NFLoadBalancer:name=localhost,current list of Servers=[],Load balancer stats=Zone stats: {},Server stats: []}ServerList:org.springframework.cloud.netflix.ribbon.eureka.DomainExtractingServerList@107dc063
2018-09-05 23:20:17.822 ERROR 47037 --- [ctor-http-nio-2] .a.w.r.e.DefaultErrorWebExceptionHandler : Failed to handle request [GET http://localhost:8080/rest-service/hello]

org.springframework.cloud.gateway.support.NotFoundException: Unable to find instance for localhost
	at org.springframework.cloud.gateway.filter.LoadBalancerClientFilter.filter(LoadBalancerClientFilter.java:72) ~[spring-cloud-gateway-core-2.0.1.RELEASE.jar:2.0.1.RELEASE]
	at org.springframework.cloud.gateway.handler.FilteringWebHandler$GatewayFilterAdapter.filter(FilteringWebHandler.java:133) ~[spring-cloud-gateway-core-2.0.1.RELEASE.jar:2.0.1.RELEASE]
	at org.springframework.cloud.gateway.filter.OrderedGatewayFilter.filter(OrderedGatewayFilter.java:44) ~[spring-cloud-gateway-core-2.0.1.RELEASE.jar:2.0.1.RELEASE]
	at org.springframework.cloud.gateway.handler.FilteringWebHandler$DefaultGatewayFilterChain.lambda$filter$0(FilteringWebHandler.java:115) ~[spring-cloud-gateway-core-2.0.1.RELEASE.jar:2.0.1.RELEASE]
	at reactor.core.publisher.MonoDefer.subscribe(MonoDefer.java:45) ~[reactor-core-3.1.8.RELEASE.jar:3.1.8.RELEASE]

Service Registry: screen shot 2018-09-06 at 12 15 05 am

Code:

PS: Works fine when the actual endpoint is provided instead of the service id.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Spring Cloud API Gateway routing not working - Stack Overflow
Spring Cloud API Gateway routing not working · 1. Add : eureka.instance.prefer-ip-address=true to application. · In your Service Configuration, ...
Read more >
8 Service routing with Spring Cloud Gateway - Spring ...
8.2.2 Configuring the Spring Cloud Gateway to communicate with Eureka ... Listing 8.6 Mapping routes manually in the gateway-server.yml file. spring: cloud: ...
Read more >
Exploring the New Spring Cloud Gateway - Baeldung
Being focused on routing requests, the Spring Cloud Gateway forwards requests to a Gateway Handler Mapping, which determines what should be done ...
Read more >
Service registration and discovery of Spring Cloud Gateway
route forwarding. This article explains how Spring Cloud Gateway cooperates with the service registry for routing and forwarding in the form of a...
Read more >
Spring Cloud Gateway
Spring Cloud Gateway requires the Netty runtime provided by Spring Boot and Spring Webflux. It does not work in a traditional Servlet Container...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found