'How to append prefix in gateway server in new spring boot 2.6.4?

Previously, I was using Spring boot 2.2.6.RELEASE with dependency spring-cloud-starter-netflix-zuul and spring cloud version Hoxton.SR3. In this for gateway server, I was using following configuration in application.yml:

zuul:
  host:
    prefix: /api
    routes:
      userapp:
        path: /userapp/**
        sensitiveHeaders: null
        serviceId: userapp

Suppose, gateway server port is 8765 and userapp port is 8080. Now, if userapp has an api http://localhost:8080/get/id/{userid}, then from gateway server, same api would be: http://localhost:8765/api/userapp/get/id/{userid}. Here, I am able to append prefix /api/userapp from the Gateway server.

Now, in new Spring boot version 2.6.4 with dependency spring-cloud-starter-gateway and spring cloud version 2021.0.1, I am using following configuration in application.yml of the Gateway server:

spring:
  cloud:
    gateway:
      discovery:
        locator:
          enabled: true
          route-id-prefix: /api/userapp
      routes:
        - id: userapp
          uri: lb://userapp/
          predicates:
          - Path=/**

Now, here I am not able to append prefix like before. I have to use http://localhost:8765/get/id/{userid} to get data from gateway server. One solution is I have to append all apis in userapp with /api/userapp, then I can use http://localhost:8765/api/userapp/get/id/{userid}.

So, how can I append different prefix for different microservices in this new Spring boot instead of appending prefix in all apis individually in all microservices.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source