RESTful Web 服务。访问资源

我有一个基本的 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


湖上湖
浏览 105回答 1
1回答

Cats萌萌

为了@RequestMapping("/api/v1/users/wallets")您指定了一个GET端点&nbsp;@GetMapping(path&nbsp;=&nbsp;"/"&nbsp;...)所以可访问的 URL 位于(见 terminating&nbsp;/)GET&nbsp;http://127.0.0.1:1133/myApp/api/v1/users/wallets/
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java