org.apache.http.conn.HttpHostConnectException:连接到localhost:8080 [localhost / 127.0.0.1]失败:连接被拒绝:connect

时间:2020-01-17 12:31:04

标签: spring-boot

我是spring-boot的新手,正在使用http API测试spring-boot应用程序,但出现连接错误。

获取http://localhost:8080/api/helloworld

org.apache.http.conn.HttpHostConnectException:连接到本地主机:8080 [localhost / 127.0.0.1]失败:连接被拒绝:连接

//HelloWorldController.java
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;


@RestController
public class HelloWorldController {
    @GetMapping(value="/api/helloworld")
    public String helloWorld(){
        return "helloworld";
    }
}

//helloworld.http    
GET http://localhost:8080/api/helloworld

而且它与运行主Java文件的效果很好。

enter image description here

请让我知道我做错了什么。谢谢。

0 个答案:

没有答案