在RestController中未找到映射

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

我有一个RestController,它定义了默认路径和一些这样的端点:

@RestController
@EnableHypermediaSupport(type = EnableHypermediaSupport.HypermediaType.HAL)
@RequestMapping(path = "/somePath", produces = "application/hal+json")
public class SomeRestController {

  @GetMapping (path = "/otherPath")
  public String someEndpoint(){
  return "hello";
  }

    ...other endpoints...
}

我为映射的端点获取404。但是,如果删除默认的RequestMapping,则端点会突然被拾取!我还尝试了端点的RequestMapping(path = ...,method = RequestMethod.GET),但结果相同...

如果我从一个端点删除@GetMapping,则会成功映射默认路径。

这里发生了什么?如果具有默认的RequestMapping,为什么不映射端点?

spring spring-boot rest spring-restcontroller
1个回答
1
投票

您必须合并两个路径:

localhost:8080/somePath/otherPath

因为类顶部的映射适用于此控制器中的所有方法,并且将添加该方法的特定路径

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