我有一个基本的 SpringBoot 2.1.3.RELEASE 应用程序。使用 Spring Initializer、JPA、嵌入式 Tomcat、Thymeleaf 模板引擎,并将其打包为可执行的 JAR 文件。我有这个 restController@RestController@RequestMapping("/api/v1/users")public class UserResourceController extends ResourceController { private static final Logger LOG = LoggerFactory.getLogger(UserResourceController.class); @GetMapping(path = "/", consumes = "application/json", produces = "application/json") @ResponseStatus(HttpStatus.OK) public ResponseEntity<User> getUser(@RequestHeader(value = "Authorization") String authHeader) { User user = authUserOnPath("/users", authHeader); user.getApplicationSetup() .setExchangeRateWithUSD(currencyService.getUSDRate(user.getApplicationSetup().getAppCcy())); return ResponseEntity.ok().body(user); }}还有这个:@RestController@RequestMapping("/api/v1/users/wallets")public class WalletResourceController extends ResourceController { @Autowired private WalletService walletService; /** * Get user's wallets * * @param request * @param id * @return */ @GetMapping(path = "/", consumes = "application/json", produces = "application/json") public ResponseEntity<List<Wallet>> getUserWallets(@RequestHeader(value = "Authorization") String authHeader) { User user = authUserOnPath("/users/wallets", authHeader); List<Wallet> wallets = userService.getWallets(user); return ResponseEntity.ok().cacheControl(CacheControl.maxAge(5, TimeUnit.MINUTES)).body(wallets); }访问时一切正常:GET http://127.0.0.1:1133/myApp/api/v1/users但我在访问时得到了 404:GET http://127.0.0.1:1133/myApp/api/v1/users/wallets
1 回答
Cats萌萌
TA贡献1805条经验 获得超9个赞
为了
@RequestMapping("/api/v1/users/wallets")
您指定了一个GET
端点
@GetMapping(path = "/" ...)
所以可访问的 URL 位于(见 terminating /
)
GET http://127.0.0.1:1133/myApp/api/v1/users/wallets/
添加回答
举报
0/150
提交
取消