【问题标题】:spring MVC errors : Could not instantiate bean class [org.springframework.data.domain.Pageable]: Specified class is an interfacespring MVC错误:无法实例化bean类[org.springframework.data.domain.Pageable]:指定的类是一个接口
【发布时间】:2014-09-20 17:06:03
【问题描述】:

我想在 Spring MVC 中进行分页但出现错误: 无法实例化 bean 类 [org.springframework.data.domain.Pageable]:指定的类是一个接口。任何人都可以帮忙吗?谢谢!

【问题讨论】:

  • 请显示有问题的代码。你想做什么?为什么spring需要实例化一个Pageable
  • 实际上我想对我的网站进行分页,一切正常,但是当我在 Spring 中使用 PagingAndSortingRepository 时出现此错误。如果你知道如何分页,请告诉我
  • 请出示代码。

标签: spring-mvc spring-data-jpa


【解决方案1】:

为了解析Pageable 参数,Spring MVC 使用了一个名为HandlerMethodArgumentResolver(参考here)的组件。专门针对 Pageable 作为参数,使用的 HandlerMethodArgumentResolver 是org.springframework.data.web.PageableHandlerMethodArgumentResolver,这可以通过添加@EnableSpringDataWebSupport 注解使用Java Configuration 注册。

更多选项在这里:http://docs.spring.io/spring-data/data-commons/docs/current/reference/html/#core.web

【讨论】:

  • 感谢您的帮助,设置后出现错误:无法自动装配字段:com.repo.ListRepo 创建名为“listController”的 bean 时出错:注入自动装配的依赖项失败;嵌套异常是 org.springframework.beans.factory.BeanCreationException: No qualifying bean of type [com.repo.ListRepo] found for dependency 。也许我在哪里配置错了,请帮助我
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-10-23
  • 1970-01-01
  • 2018-09-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多