#StackBounty: #spring-cloud #spring-cloud-gateway How to pass RouteLocatorBuilder route to specific uri

Bounty: 50

I have written a route builder like following

@Bean
fun gateways(rlb: RouteLocatorBuilder): RouteLocator {
    return rlb.routes()
        .route { 
            it.path("/users").uri("lb://demo-service-1/users")
        }.build()
}

this works fine. But when I change the path but keep the uri same I get 404 when I visit the /userlist from browser

it.path("/userlist").uri("lb://demo-service-1/users")

I look in the debug log and see it is querying /userlist in the downstream.

2021-07-09 20:53:10.697 DEBUG 5616 --- [ctor-http-nio-5] r.netty.http.client.HttpClientConnect    : [id:bd31ce68-1, L:/127.0.0.1:50907 - R:localhost/127.0.0.1:8081] Handler is being applied: {uri=http://DESKTOP-AM2LB9I:8081/userlist, method=GET}

Why is this happening?

What is the right way to write this?

Spring boot version "2.5.3"


Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.