我正在尝试使用 Spring Cloud 的 Open Feign 调用另一个服务,但这是我不断得到的响应:
{
"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();
}
}