【问题标题】:unable to reach request mapping endpoint so im getting 404 error无法到达请求映射端点,所以我收到 404 错误
【发布时间】: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

标签: java spring spring-boot maven jpa


【解决方案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));
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-27
    • 1970-01-01
    • 2016-06-30
    • 2012-05-28
    相关资源
    最近更新 更多