Feign не разрешает имя - PullRequest
0 голосов
/ 14 января 2020

Я пытаюсь вызвать другую службу, используя Open Feign Spring Cloud, но вот ответ, который я получаю:

{
  "timestamp": 1579015052962,
  "status": 500,
  "error": "Internal Server Error",
  "message": "auth-service: Name or service not known executing GET http://auth-service/api/v1/auth",
  "path": "/api/v1/event"
}

Вот мой код:

package com.eventmanager.events.client;

import com.eventmanager.events.client.mappings.Auth;
import com.eventmanager.events.config.CustomFeignClientConfig;
import com.eventmanager.events.responses.Response;

import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;

@FeignClient(name = "auth-service", configuration = CustomFeignClientConfig.class)
public interface AuthClient {
  @GetMapping("/api/v1/auth")
  public Response<Auth> getLoggedUser(@RequestHeader(value = "Authorization") String authorization);
}

Я настроил Feign на используйте клиент OkHttp, и я не уверен, что он ответственен за ошибку:

package com.eventmanager.events.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import feign.okhttp.OkHttpClient;

@Configuration
public class CustomFeignClientConfig {
  @Bean
  public OkHttpClient client() {
    return new OkHttpClient();
  }
}

1 Ответ

0 голосов
/ 14 января 2020

Может быть потому, что вы не указали базовый URL. для клиента и принимает базовый URL-адрес в качестве службы авторизации.

@FeignClient(name = "auth-service", configuration = CustomFeignClientConfig.class, url = "http://lcoalhost:8080")
public interface AuthClient {
  @GetMapping("/api/v1/auth")
  public Response<Auth> getLoggedUser(@RequestHeader(value = "Authorization") String authorization);
}
...