0

我正在尝试基于spring-restdocs生成一个 Rest API 文档

在以下代码中,我在apply()处收到编译时错误

未定义类型 DefaultMockMvcBuilder 的方法 apply(RestDocumentationMockMvcConfigurer)

@ContextConfiguration(locations = { "classpath:/testApplicationRestService.xml" })
@RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration
public class CustomerControllerTest {

    @Rule
    public final RestDocumentation restDocumentation = new RestDocumentation(
            "build/generated-snippets");

    @Autowired
    private WebApplicationContext context;
    private MockMvc mockMvc;

    @Before
    public void setUp() {

        this.mockMvc = MockMvcBuilders.webAppContextSetup(this.context)
                .apply(documentationConfiguration(this.restDocumentation))
                .build();
    }

}
4

1 回答 1

2

Spring REST Docs 需要 Spring Fanework 4.1 或更高版本。该apply方法是 Spring Framework 4.1 中的新方法。编译失败意味着您在类路径上有一个早期版本。您应该更新您的 pom.xml 或 build.gradle 以确保您使用的是所需的版本。

于 2015-10-11T21:35:50.477 回答