Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/343.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java springboot中的本地主机连接被拒绝_Java_Spring Boot_Httprequest_Spring Restcontroller_Request Mapping - Fatal编程技术网

Java springboot中的本地主机连接被拒绝

Java springboot中的本地主机连接被拒绝,java,spring-boot,httprequest,spring-restcontroller,request-mapping,Java,Spring Boot,Httprequest,Spring Restcontroller,Request Mapping,我对springboot不熟悉。我有一个控制器类,如下所示 package com.example.controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @RestController public class Controller { @RequestMappin

我对springboot不熟悉。我有一个控制器类,如下所示

package com.example.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class Controller {
    @RequestMapping("/hello")
    public String getHi() {
        return "Hi";
    }
}

运行该项目后,我尝试在浏览器中打开“localhost:8080/hello”,但本地主机连接被拒绝。在控制台中,我可以看到,Tomcat服务器是用8080端口启动的。 提前谢谢

更新 我通过在我的主课下面添加一行来解决我的问题

@Autowired
    Controller controller;

尝试访问127.0.0.1:8080/hello以确保环回有效

@RequestMapping
@randytan上添加
@RequestMapping(value=“/hello”,method=RequestMethod.GET)
但不更改检查端口
8080
是否未被其他应用程序使用。或者添加
server.port=8082
以使用以下url在另一个端口上测试您的应用程序:
localhost:8082/hello
@HarryCoder我尝试使用8082端口。这一次我得到了“白标错误页面”,该链接可以回答您的问题:
Starting service [Tomcat]
Starting Servlet engine: [Apache Tomcat/9.0.46]
Initializing Spring embedded WebApplicationContextRoot WebApplicationContext: initialization completed in 626 ms
Tomcat started on port(s): 8080 (http) with context path ''
@Autowired
    Controller controller;