我有一个基本的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
答案 0 :(得分:0)
对于
@RequestMapping("/api/v1/users/wallets")
您在以下位置指定了GET
端点
@GetMapping(path = "/" ...)
因此可访问的URL位于(请参阅终止/
)
GET http://127.0.0.1:1133/myApp/api/v1/users/wallets/