java - Maven构建成功但仍然出现404错误未找到

标签 java spring spring-boot maven spring-mvc

所以我正在尝试做 https://spring.io/guides/gs/rest-service/#scratch指南,我正在通过“运行为”“maven build”来安装 Maven 项目,并在目标选项中进行干净安装。我不知道出了什么问题。我还使用 m2e 插件来运行 maven 构建,因为我搜索了其他答案,人们说使用 eclipse maven 命令行很糟糕。

但是我在 http://localhost:8080/greeting 的浏览器中收到此错误

HTTP 状态 404 – 未找到 类型状态报告

留言/问候语

说明源服务器未找到目标资源的当前表示或不愿意透露该表示的存在。

Apache Tomcat/9.0.31

构建成功:

https://pastebin.com/QJtxyjxV

我将其粘贴到此处,因为堆栈溢出将其标记为垃圾邮件,并且我再次粘贴了几行代码,因为链接未被接受:/

mockHttpServletRequest:
      HTTP Method = GET
      Request URI = /greeting
       Parameters = {}
          Headers = []
             Body = null
    Session Attrs = {}

Handler:
             Type = com.example.restservice.GreetingController
           Method = com.example.restservice.GreetingController#greeting(String)

Async:
    Async started = false
     Async result = null

Resolved Exception:
             Type = null

ModelAndView:
        View name = null
             View = null
            Model = null

FlashMap:
       Attributes = null

MockHttpServletResponse:
           Status = 200
    Error message = null
          Headers = [Content-Type:"application/json"]
     Content type = application/json
             Body = {"id":1,"content":"Hello, World!"}
    Forwarded URL = null
   Redirected URL = null
          Cookies = []

MockHttpServletRequest:
      HTTP Method = GET
      Request URI = /greeting
       Parameters = {name=[Spring Community]}
          Headers = []
             Body = null
    Session Attrs = {}

Handler:
             Type = com.example.restservice.GreetingController
           Method = com.example.restservice.GreetingController#greeting(String)

Async:
    Async started = false
     Async result = null

Resolved Exception:
             Type = null

ModelAndView:
        View name = null
             View = null
            Model = null

FlashMap:
       Attributes = null

MockHttpServletResponse:
           Status = 200
    Error message = null
          Headers = [Content-Type:"application/json"]
     Content type = application/json
             Body = {"id":2,"content":"Hello, Spring Community!"}
    Forwarded URL = null
   Redirected URL = null
          Cookies = []

最佳答案

除了 Maven 构建之外,还运行启动应用程序的 Spring Boot 应用程序类。在项目级别运行以下命令。

mvn spring-boot:run

如果您使用任何 IDE,请右键单击 Spring boot 应用程序类并调用“运行应用程序”。

关于java - Maven构建成功但仍然出现404错误未找到,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60197433/

相关文章:

java - Junit 测试控制台中的输出

java - 通过 SQL "select * from "从 java 存储过程返回结果集

java - 文本字段未按预期工作。 java

java - 如果条件不适用于相关实体

java - 如何使 kotlin 中的主要 java 方法更简单?

java - 从 JHipster 开始

java - Hibernate JPA,重复的子结果?

css - 无法使用 spring 提供静态资源,而是接收索引

java - Spring MockMvc 测试 : NullPointerException for mvc. perform()

java - 在 OpenShift 上部署时出错