【问题标题】:Pageable in controller not instantiated控制器中的可分页未实例化
【发布时间】:2016-09-16 19:56:34
【问题描述】:

我有一个带有控制器的 spring-boot 应用程序,它使用 Pageable 作为其方法之一的参数。它工作正常。但我想使用 spring-contract-verifier 来生成和执行测试。 测试的基类如下所示:

public class MvcTest {

    @Before
    public void setup() {
        RestAssuredMockMvc.standaloneSetup(new Controller());
    }
}

我得到的例外是:

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.domain.Pageable]: Specified class is an interface
    at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:99)

我搜索了SO,发现我应该添加

@EnableSpringDataWebSupport

到我的配置类。我创建了一个类:

@Configuration
@EnableWebMvc
@EnableSpringDataWebSupport
public class WebConfig {
}

但是,我不确定如何告诉合同验证者将此类拉入配置。 谢谢

【问题讨论】:

  • 不是您的问题的答案,但我很确定您不是要导入 java.awt.print.Pageable
  • 已更正,但问题仍然存在。

标签: spring testing


【解决方案1】:

这是错误的可分页:使用org.springframework.data.domain.Pageable 而不是java.awt.print.Pageable

您需要启用

 @EnableSpringDataWebSupport

 <bean class="org.springframework.data.web.config.SpringDataWebConfiguration" />

@见:http://docs.spring.io/spring-data/jpa/docs/current/reference/html/#core.web

【讨论】:

  • [删除了我原来的评论,因为编辑后答案看起来不再像一个疯狂的猜测;)]
  • 根据我最初的帖子 - @EnableSpringDataWebSupport 已经存在。
猜你喜欢
  • 2014-04-06
  • 2015-01-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-06-02
  • 1970-01-01
相关资源
最近更新 更多