【问题标题】:Spring Boot - webservice: Connection RefusedSpring Boot - 网络服务:连接被拒绝
【发布时间】:2016-10-18 11:22:30
【问题描述】:

我正在尝试实现 spring 文档中给出的 spring boot webservice 应用程序:

https://spring.io/guides/gs/consuming-web-service/

构建成功,请求和响应 java 文件被创建,但是当执行 spring-boot:run 时,它给出了

Caused by: org.springframework.ws.client.WebServiceIOException: I/O error: Connection refused: connect; nested exception is java.net.ConnectException: Connection refused: connect
    at org.springframework.ws.client.core.WebServiceTemplate.sendAndReceive(WebServiceTemplate.java:561)
    at org.springframework.ws.client.core.WebServiceTemplate.marshalSendAndReceive(WebServiceTemplate.java:390)
    at hello.WeatherClient.getCityForecastByZip(WeatherClient.java:30)
    at hello.Application.main(Application.java:20)

但是可以通过 Eclipse 中的 Web 浏览器访问该 URL。请帮我解决这个问题

【问题讨论】:

  • 您是否在通过公司代理访问互联网的公司网络中?您是否设置了访问互联网的代理设置?

标签: spring web-services spring-boot


【解决方案1】:

您尝试调用的 Web 服务 URL 可能无法访问或超时。确保 Web 服务 URL 路径正确且正在侦听。还要验证设置的超时持续时间和请求所用的时间。

PS. Also check if there is some firewall issue at Server side.

对于防火墙问题,您可能需要在客户端代码中提供代理详细信息(proxyHost 和 proxyPort)。

编辑:

我找不到合适的博客或能更好地解释它的东西。但在 stackoverflow 上发现了一个类似答案的问题:here

【讨论】:

  • 你能分享一些链接吗,我可以在哪里检查和更正我的代理设置?
  • 你验证过webservice url和port没问题吗?
  • 是的,很好。我已经添加了
  • ` System.setProperty("proxyHost", "yourproxy.server.com"); System.setProperty("proxyPort", "8080");'
【解决方案2】:

确保您声明的所有测试都使用相同的 @SpringBootTest 注释参数。 由于两个测试中的参数不同,我遇到了同样的问题。当我将所有注释都设置为相同时,问题就消失了: @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-10-10
    • 2020-01-19
    • 2011-06-24
    • 2020-07-26
    • 2020-12-31
    • 1970-01-01
    • 2018-09-22
    相关资源
    最近更新 更多