Groovy Spring Boot REST服务正在为有效路径抛出PageNotFound错误

问题描述 投票:0回答:1

我创建了一个完全重现此错误的spring-boot-troubleshooting repo on GitHub

我正在构建一个基于Spring Boot的REST服务,它只暴露RESTful API端点,完全没有UI /视图/ HTML页面。

您可以在该repo的build.gradle中看到我依赖的唯一两个Spring Boot依赖项是:

,'org.springframework.boot:spring-boot-starter-jetty'
,'org.springframework.boot:spring-boot-starter-actuator'

所以没有视图相关(Thymeleaf等)。

当您运行该应用程序并打开浏览器转到FizzbuzzResource URL时,您将获得:

Problem accessing /error. Reason:

Not Found

然后在控制台上你会看到:

WARN  o.s.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/v1/fizzbuzz/12345] in DispatcherServlet with name 'dispatcherServlet'

我想知道为什么Spring会抱怨基于HTML的PageNotFound错误,这应该是一个纯粹的REST服务,当然,我很想知道解决这个问题的方法是让它正常运行并正确返回我的Fizzbuzz资源!

spring spring-boot groovy thymeleaf
1个回答
0
投票

您需要启用web mvc并使ApiVersionRequestMappingHandlerMapping容器中的bean,否则Spring将不会使用您的ApiVersionRequestMappingHandlerMapping#getMappingForMethod

看到我的提交https://github.com/yaoReadingCode/spring-boot-troubleshooting/commit/6260c394f4c28d155bbf016a758f3d37a5682a9c

© www.soinside.com 2019 - 2024. All rights reserved.