我正在尝试使用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();
}
}发布于 2020-08-31 02:20:58
如果你正在使用Finchey.SR1,你可以检查这个https://stackoverflow.com/a/52727544在那个云版本中的ContentPath似乎有一个问题。
发布于 2020-01-15 00:46:55
可能是因为您尚未指定基URL。对于客户端&它将基本URL作为auth-service。
@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);
}https://stackoverflow.com/questions/59736964
复制相似问题