【问题标题】:Failed to instantiate [org.springframework.data.domain.Pageable]: Specified class is an interface无法实例化[org.springframework.data.domain.Pageable]:指定的类是一个接口
【发布时间】:2015-02-03 18:07:55
【问题描述】:

当我发送像getUserPlaces?page=0&size=5 这样的请求时 我收到此错误:

无法实例化[org.springframework.data.domain.Pageable]:指定的类是一个接口

我的控制器是:

@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" />

我错过了什么?

【问题讨论】:

  • 我认为@EnableSpringDataWebSupport 应该在一个不在此处的配置类中
  • 在什么配置类上?
  • this 可能是相关的。
  • @lifus 可能是,但是当我粘贴 意思是 这里不允许。可能是因为我使用的是 Spting 4+,不知道,你能帮我解决这个问题吗?
  • 看看thisthis。作为@RC。提到,你不需要像EnableSpringDataWebSupportespecially on controllers这样的注释。

标签: java spring spring-mvc


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 2014-09-20
    • 1970-01-01
    • 2017-10-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-12
    • 1970-01-01
    相关资源
    最近更新 更多