尝试访问资源 url 时 Spring Boot 中的 Http 404 [英] Http 404 in Spring Boot while trying to access resource url
问题描述
我开发了一个 Spring Boot REST API,URL 是:http://localhost:8080/greeting
I developed a Spring Boot REST API and the URL is: http://localhost:8080/greeting
但是,当我尝试访问它时,它说
However, when I'm trying to access it, it says
白标错误页面此应用程序没有明确的映射/error,因此您将其视为后备.美国东部时间 3 月 19 日星期一 22:06:542018 出现意外错误(类型=未找到,状态=404).否消息可用
Whitelabel Error Page This application has no explicit mapping for /error, so you are seeing this as a fallback. Mon Mar 19 22:06:54 EDT 2018 There was an unexpected error (type=Not Found, status=404). No message available
这是我使用的示例:https://spring.io/guides/gs/rest-service/
推荐答案
造成这种情况的原因有 3 个
There are 3 reasons for this to happen
- 1 :您没有促进
ErrorController
的任何错误处理.(最推荐) - 2 : 你没有明确设置
server.error.whitelabel.enabled=false
在您的应用程序属性.(只是初学者的解决方案) - 3 : 你的
@SpringBootApplication
配置的类与您的级别相同控制器.例如
- 1 : you did not facilitate any error handling by
ErrorController
. (most recommended) - 2 : You did not explicitly set
server.error.whitelabel.enabled=false
in your application.properties. (just a solutions for beginners) - 3 : Your
@SpringBootApplication
configured class is at same level as your controller. e.g.
src/main/java/com/myPackage/--启动应用程序--RestController
您可以将 BootApplication 保留在层次结构中的上一级,它也可以解决您的问题(根本不推荐使用此解决方案.它只是一个选项,因此要让您知道).
You can keep BootApplication one level above in hierarchy and it will also solve your issue (this solution is not at all recommended. It just a option and so to let you know).
这篇关于尝试访问资源 url 时 Spring Boot 中的 Http 404的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!