所以我正在尝试做 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
构建成功:
我将其粘贴到此处,因为堆栈溢出将其标记为垃圾邮件,并且我再次粘贴了几行代码,因为链接未被接受:/
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/