控制器中的可分页未实例化

use*_*285 3 testing spring

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

public class MvcTest {

    @Before
    public void setup() {
        RestAssuredMockMvc.standaloneSetup(new Controller());
    }
}
Run Code Online (Sandbox Code Playgroud)

我得到的例外是:

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)
Run Code Online (Sandbox Code Playgroud)

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

@EnableSpringDataWebSupport
Run Code Online (Sandbox Code Playgroud)

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

@Configuration
@EnableWebMvc
@EnableSpringDataWebSupport
public class WebConfig {
}
Run Code Online (Sandbox Code Playgroud)

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

Ral*_*lph 5

错误的分页:使用org.springframework.data.domain.Pageable代替java.awt.print.Pageable

您需要启用

 @EnableSpringDataWebSupport
Run Code Online (Sandbox Code Playgroud)

要么

 <bean class="org.springframework.data.web.config.SpringDataWebConfiguration" />
Run Code Online (Sandbox Code Playgroud)

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