无法到达请求映射端点,所以我收到 404 错误
Posted
技术标签:
【中文标题】无法到达请求映射端点,所以我收到 404 错误【英文标题】:unable to reach request mapping endpoint so im getting 404 error 【发布时间】:2021-09-13 08:15:03 【问题描述】:我创建了一个带有请求映射“/route”的新控制器,但无论我做什么,我都无法到达端点localhost:8080/route
。我总是得到 404。
如何在不出现 404 的情况下访问端点路由?
@RestController
public interface RouteController
@ApiOperation(value = "Add a route details to adapter", nickname = "addroute", notes = "Add route details to the table and Send it to ATLAS", tags =
"route", )
@ApiResponses(value =
@ApiResponse(code = 200, message = "Successful Insertion into DB and Proceded for Transformation"),
@ApiResponse(code = 405, message = "Invalid Input") )
@RequestMapping(value = "/route", produces = "application/json" , consumes =
"application/json" , method = RequestMethod.POST)
public ResponseEntity<Void> createData(
@ApiParam(value = "Route Array", required = true) @Valid @RequestBody RouteArray routeArray) ;
实现类
public class RouteControllerImpl implements RouteController
@Autowired
private RouteService routeService;
@Override
public ResponseEntity<Void> createData(@ApiParam(value = "Route Details", required = true) @Valid @RequestBody RouteArray routeArray)
return new ResponseEntity<Void>(routeService.transformRoute(routeArray));
【问题讨论】:
你能检查你的应用程序上下文路径吗? (您可以在控制台日志中找到它) 注解不适用于接口。尝试将所有注释移至Impl
类
org.springframework.core.log.LogFormatUtils: POST "/route", parameters= springfox.documentation.spring.web.PropertySourcedRequestMappingHandlerMapping: 查找路径处理程序:/route org.springframework。 web.servlet.handler.AbstractHandlerMapping: 映射到 ResourceHttpRequestHandler [Classpath [META-INF/resources/], Classpath [resources/], Classpath [static/], Classpath [public/], ServletContext [/]] resource.ResourceHttpRequestHandler: Resource未找到 FrameworkServlet:已完成 404 NOT_FOUND
【参考方案1】:
您需要在实施中进行一些更改。您不应将 @RestController 与 OpenAPI api 一起使用,而应使用 @Api 注释。您应该在实现此 API 的类上使用 @RestController。
@Validated
@Api(
value = "route",
description = The Controller API"
)
public interface RouteController
@ApiOperation(value = "Add a route details to adapter", nickname = "addroute", notes = "Add route details to the table and Send it to ATLAS", tags =
"route", )
@ApiResponses(value =
@ApiResponse(code = 200, message = "Successful Insertion into DB and Proceded for Transformation"),
@ApiResponse(code = 405, message = "Invalid Input") )
@RequestMapping(value = "/route", produces = "application/json" , consumes =
"application/json" , method = RequestMethod.POST)
public ResponseEntity<Void> createData(
@ApiParam(value = "Route Array", required = true) @Valid @RequestBody RouteArray routeArray) ;
实施:
@RestController
public class RouteControllerImpl implements RouteController
@Autowired
private RouteService routeService;
@Override
public ResponseEntity<Void> createData(@Valid RouteArray routeArray)
return new ResponseEntity<Void>(routeService.transformRoute(routeArray));
【讨论】:
以上是关于无法到达请求映射端点,所以我收到 404 错误的主要内容,如果未能解决你的问题,请参考以下文章
如何修复 axios Next js 中的“错误:请求失败,状态码为 404”
HTTP 错误 404.3 - Not Found 由于扩展配置问题而无法提供您请求的页面。如果该页面是脚本,请添加处理程序。如果应下载文件,请添加 MIME 映射。
HTTP 错误 404.3 – Not Found 由于扩展配置问题而无法提供您请求的页面。如果该页面是脚本,请添加处理程序。如果应下载文件,请添加 MIME 映射。
HTTP 错误 404.3 - 未找到 - 由于扩展配置,无法提供您请求的页面
HTTP 错误 404.3 – Not Found 由于扩展配置问题而无法提供您请求的页面。如果该页面是脚本,请添加处理程序。如果应下载文件,请添加 MIME 映射。