2

I am having a small issue in getting the Zuul route config correct. Here's what I have currently

 zuul:
  routes:
    microservice:
      path: /service/*
      serviceId: session
      sensitiveHeaders: Cookie,Set-Cookie,Authorization
microservice:
  ribbon:
    listOfServers: localhost:8090

At the Microservice i have a Restcontroller like this:

@RestController
@RequestMapping("/service")

I have multiple end points in the RestController, for example:

@RequestMapping(method = { RequestMethod.GET}, value = "/service1", produces = "application/json")

Now when I send a request like localhost:8080/service/service1 it does not hit the expected endpoint. It routes the request to localhost:8090/service1 (where nothing is running).

It works well if I change the context path like this

@RestController
@RequestMapping("/service")

to

@RestController
@RequestMapping("/")

I have tried changing the path from path: /service/*
to

path: /service/**

but no effect.

The other option is to force the routing at the filter level, but I think it should be possible to route localhost:8080/service/service1 to the microservice directly. Any suggestions on how I can get this done in the Zuul configuration.

I cannot use the URL option since it is not compatible with the fallback that I am working with.

g00glen00b
  • 41,995
  • 13
  • 95
  • 133
vasanth
  • 81
  • 7

2 Answers2

1

The easiest way to get it done is by stopping the prefix stripping; looks like it is enabled by default.

path: /service/**
stripPrefix: false
vasanth
  • 81
  • 7
0

The routing key is not intended to be the part of the target url. For example, /service/** path will use the expression to route requests to the mapped service with the path mentioned after the expression which is "/service1". If the routing key is required as part of the target url too, stripPrefix needs to be be set to false.

Mukesh
  • 1
  • 1