java - 无法实例化[org.springframework.data.domain.Pageable] : Specified class is an interface

标签 java spring spring-mvc

当我发送诸如 getUserPlaces?page=0&size=5 之类的请求时 我收到此错误:

Failed to instantiate [org.springframework.data.domain.Pageable]: Specified class is an interface

我的 Controller 是:

@Controller
@EnableSpringDataWebSupport
public class UserController {
...
@RequestMapping(value = "/getUserPlaces", method = RequestMethod.POST)
public @ResponseBody List<PlaceDto> getUserPlaces(@RequestBody RoutePagingDto routeRequest, Pageable pageable) {
    return placeService.placeToPlaceDto(userService.getUserPlaces(pageable));
}

在我的 spring-context.xml 中,我将它们声明为 beans:

<beans:bean class="org.springframework.data.web.SortHandlerMethodArgumentResolver" />

<beans:bean class="org.springframework.data.web.PageableHandlerMethodArgumentResolver" />

我缺少什么?

最佳答案

从 UserController 类中删除 @EnableSpringDataWebSupport 并使用以下代码创建 WebConfig 类

@Configuration
@EnableWebMvc
@EnableSpringDataWebSupport
public class WebConfig extends WebMvcConfigurationSupport {}

关于java - 无法实例化[org.springframework.data.domain.Pageable] : Specified class is an interface,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28305786/

相关文章:

java - 我应该使用 cacerts 还是本地 trustore 但不能同时使用两者?

java - Android - 在 if else 语句之间使用相同的变量值

java - 何时在 Spring Boot 中使用自定义上下文路径而不是根上下文

spring - 带逗号的假调用 URL

java - Spring表单绑定(bind)下拉对象

java - 我应该应用多少测试来测试双向链表?

java - 我想在表中插入数组值来完成此任务,我必须创建动态插入查询。如何执行它?

java - 我可以使用 Spring Security @PreAuthorize 来检查 HTTP header 吗?

java - Spring MVC 图片上传使用 Mockmvc 和 JSON 集成测试失败

java - 来自 HttpServletResponse 的 Spring MVC 相对重定向