首页 > 解决方案 > 在 Spring 中尝试对控制器进行 REST GET 调用时出现 404 错误

问题描述

我正在尝试使用 Spring 对本地 Tomcat9 服务器进行 REST 调用。我的控制器如下。

@RestController
public class HelloWorldController {

    @RequestMapping(method=RequestMethod.GET, path="/hello-world")
    public String helloWorld() {
        return "Hello World";
    }
}

但是,当我尝试使用 url 进行 REST 请求时http://localhost:8080/hello-world,我收到以下 404 错误:

The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.

我该如何解决这个问题?我正在尝试使用 Spring 进行更多练习。

工作区截图

编辑:我解决了这个问题。我停止了 Tomcat 服务器并将 RestfulWebServicesApplication 作为 Java 应用程序运行。

标签: springresttomcat

解决方案


推荐阅读