简体   繁体   English

TestRestTemplate HttpHostConnectException:连接到本地主机:8082 [localhost/127.0.0.1] 失败:连接被拒绝

[英]TestRestTemplate HttpHostConnectException: Connect to localhost:8082 [localhost/127.0.0.1] failed: Connection refused

I just clone source code from https://github.com/eugenp/tutorials/tree/master/spring-resttemplate and can't execute test givenFooService_whenCallHeadForHeaders_thenReceiveAllHeaders() locally.我只是从https://github.com/eugenp/tutorials/tree/master/spring-resttemplate克隆源代码,无法在本地执行测试givenFooService_whenCallHeadForHeaders_thenReceiveAllHeaders()

I received next exception我收到下一个例外

org.springframework.web.client.ResourceAccessException: I/O error on HEAD request for "http://localhost:8082/spring-rest/foos": Connect to localhost:8082 [localhost/127.0.0.1] failed: Connection refused (Connection refused); nested exception is org.apache.http.conn.HttpHostConnectException: Connect to localhost:8082 [localhost/127.0.0.1] failed: Connection refused (Connection refused)
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:748)
    at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:674)
    at org.springframework.web.client.RestTemplate.headForHeaders(RestTemplate.java:366)
    at org.springframework.boot.test.web.client.TestRestTemplate.headForHeaders(TestRestTemplate.java:279)
    at com.baeldung.web.test.TestRestTemplateBasicLiveTest.givenFooService_whenCallHeadForHeaders_thenReceiveAllHeaders(TestRestTemplateBasicLiveTest.java:98)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69)
    at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
    at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:220)
    at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:53)
Caused by: org.apache.http.conn.HttpHostConnectException: Connect to localhost:8082 [localhost/127.0.0.1] failed: Connection refused (Connection refused)

Additional info about repository https://www.baeldung.com/spring-boot-testresttemplate关于存储库https://www.baeldung.com/spring-boot-testresttemplate的附加信息

It's strange that tutorials examples not works properly.教程示例无法正常工作很奇怪。

These are integration tests.这些是集成测试。 You need to start the spring boot app before executing the tests.在执行测试之前,您需要启动 spring 启动应用程序。 Main class - RestTemplateConfigurationApplication主要 class - RestTemplateConfigurationApplication

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 HttpHostConnectException:连接到 localhost:2375 [localhost/127.0.0.1] 失败:连接被拒绝 - HttpHostConnectException: Connect to localhost:2375 [localhost/127.0.0.1] failed: Connection refused 无法执行 HTTP 请求:连接到 localhost:8000 [localhost/127.0.0.1] 失败:连接被拒绝(连接被拒绝) - Unable to execute HTTP request: Connect to localhost:8000 [localhost/127.0.0.1] failed: Connection refused (Connection refused) org.apache.http.conn.HttpHostConnectException:连接到127.0.0.1:7055 [/127.0.0.1]失败:连接被拒绝:connect - org.apache.http.conn.HttpHostConnectException: Connect to 127.0.0.1:7055 [/127.0.0.1] failed: Connection refused: connect java.net.ConnectException:无法连接到 localhost/127.0.0.1(端口 80):连接失败:ECONNREFUSED(连接被拒绝) - java.net.ConnectException: failed to connect to localhost/127.0.0.1 (port 80): connect failed: ECONNREFUSED (Connection refused) 无法连接到服务器:localhost / 127.0.0.1:9000:尝试一次失败。 java.net.ConnectException:连接被拒绝 - Failed to connect to server: localhost/127.0.0.1:9000: try once and fail. java.net.ConnectException: Connection refused org.apache.http.conn.HttpHostConnectException:拒绝连接到http:// localhost - org.apache.http.conn.HttpHostConnectException: Connection to http://localhost refused Appium:连接到127.0.0.1:4723 [/127.0.0.1]失败:连接被拒绝:connect - Appium: Connect to 127.0.0.1:4723 [/127.0.0.1] failed: Connection refused: connect finishConnect(..) 失败:连接被拒绝:localhost/127.0.0.1,错误:Webflux、Webclient、Spring 启动、java - finishConnect(..) failed: Connection refused: localhost/127.0.0.1 , error: Webflux, Webclient, Spring boot, java 如何修复“nodetool:无法连接到'localhost:7199' - ConnectException:'连接被拒绝(连接被拒绝)'。” - how to fix “nodetool: Failed to connect to 'localhost:7199' - ConnectException: 'Connection refused (Connection refused)'.” RMI连接被拒绝与本地主机 - Rmi connection refused with localhost
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM