【问题标题】:ResourceAccessException when trying to execute a post service尝试执行后期服务时出现 ResourceAccessException
【发布时间】:2020-02-16 16:13:57
【问题描述】:

我遇到了这个异常 org.springframework.web.client.ResourceAccessException \"http://host.docker.internal:8073/user-management/users/login\" 的 POST 请求出现 I/O 错误:连接超时:连接;嵌套异常是 java.net.ConnectException: Connection timed out: connect", 我的代码是这样的

@Resource(name="restTemp")
    private RestTemplate restTemplate;

String url = "user-management/users/login";
        //String fullUrl = "https://localhost:8073/user-management/users/login";
        InstanceInfo instance = eurekaClient.getNextServerFromEureka("user-management", false);
        LoginRequest user =  restTemplate.postForObject(instance.getHomePageUrl()+url, loginRequest, LoginRequest.class);

我也不明白为什么 instance.getHomePageUrl() 会生成一个内部 docker url 。这个 docker 桌面运行的原因可能是什么。 我需要帮助来解决这个异常。根据我可以发现,当我们尝试访问第三方 url 时会发生此异常

【问题讨论】:

标签: java rest spring-boot resttemplate


【解决方案1】:

只需尝试增加 RestTemplate 发送的请求的上下文超时

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-29
    • 1970-01-01
    • 2021-10-15
    • 1970-01-01
    相关资源
    最近更新 更多