spring-restdocs is not recognizing apply()

怎甘沉沦 提交于 2019-12-12 03:24:51

问题


I am trying to generate a Rest API documentation based on spring-restdocs

In following code I am getting a compile time error at apply()

The method apply(RestDocumentationMockMvcConfigurer) is undefined for the type DefaultMockMvcBuilder

@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();
    }

}

回答1:


Spring REST Docs requires Spring Franework 4.1 or later. The apply method is new in Spring Framework 4.1. The compile failure means that you have an earlier version on the classpath. You should update your pom.xml or build.gradle to ensure that you're using the required version.



来源:https://stackoverflow.com/questions/33052007/spring-restdocs-is-not-recognizing-apply

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!