0

I have an error when starting SpringBootApplication: Unexpected exception during bean creation; nested exception is java.lang.IllegalArgumentException: url values must be not be absolute.

I'm a beginner is SpringCloud, but I worked with Openshift (On first look it's basically the same things).

I have a cluster with GatewayApplication and some business microservices in it, wrote on Kotlin. Inside cluster microservices communicate by FeignClient without authentification. In consumer-service it looks like it:

@FeignClient(name = "producer-service")
@Headers("Content-Type: application/json")
interface MarketServiceFeign {

    @GetMapping("https://somehost.ru/{id}/orders")
    fun getUserDevices(
            @PathVariable id: String,
    ): ResponseEntity<List<UserOrder>>

}

I tried find same case, but couldn't.

I tried to:

  • use @RequestLine from feign-core, but it doesn't work with @FeignClient
  • use feign.@Param for argument instead of org.springframework.web.bind.annotation.@PathVariable
  • use url with http instead of https
JavaSash
  • 19
  • 4

2 Answers2

0

The thing I didn't take into account is that FeignClient goes to services into cluster by name, not by host. So I fixed it like that:

@FeignClient(name = "producer-service")
@Headers("Content-Type: application/json")
interface MarketServiceFeign {
    @GetMapping("/{id}/orders")
    fun getUserDevices(
            @PathVariable id: String
    ): ResponseEntity<List<UserDevice>>
}

How I understand, instead of "https://somehost.ru" FeignClient uses service name "producer-service". Result url for FeignClient is "producer-service/{id}/orders".

I hope this helps someone.

JavaSash
  • 19
  • 4
0

If you want to use an absolute URL instead of using load-balancing, you need to pass it via the url attribute in the @FeignClient annotation. It's going to be a URL per Feign client, so you cannot pass it per-request via @RequestMapping annotations. You can only use them to provide the path segments that follow the host url. If you do not pass the url in @FeignClient, the name will be used as serviceId to fetch all the instances of that service (for example, from a service registry) and load-balancing will be performed under the hood to select an instance to send the request to.

OlgaMaciaszek
  • 3,662
  • 1
  • 28
  • 32