无法实例化UriInfo指定类是一个接口

时间:2017-07-29 16:55:39

标签: java spring rest spring-boot

我想使用注释@Context来检索URI

@GetMapping(value = "/profile/{username}", produces = MediaType.APPLICATION_JSON_VALUE)
public Response getProfile(
        @PathVariable String username,
        @Context UriInfo uriInfo
) {
    return Optional
            .ofNullable(userService.findOneByUsername(username))
            .map(user -> Response
                          .created(uriInfo.getAbsolutePathBuilder().path(username).build())
                          .status(Response.Status.OK)
                          .entity(user).build())
            .orElseGet(() -> {
                throw new ProfileNotFoundException();
            });
}

但是,显示页面时会抛出异常

org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.ws.rs.core.UriInfo]: Specified class is an interface

我找不到有关如何修复的信息。

1 个答案:

答案 0 :(得分:0)

UriInfo不是Spring MVC的一部分。你可以在Spring MVC中使用@RequestParam来实现这个