问题
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