Tag: spring restdocs

Spring REST模拟上下文路径

我尝试使用以下代码片段为spring rest mocks设置上下文路径: private MockMvc mockMvc; @Before public void setUp() { this.mockMvc = MockMvcBuilders.webAppContextSetup(this.context) .apply(documentationConfiguration(this.restDocumentation)) .alwaysDo(document(“{method-name}/{step}/”, preprocessRequest(prettyPrint()), preprocessResponse(prettyPrint()))) .build(); } @Test public void index() throws Exception { this.mockMvc.perform(get(“/”).contextPath(“/api”).accept(MediaTypes.HAL_JSON)) .andExpect(status().isOk()) .andExpect(jsonPath(“_links.business-cases”, is(notNullValue()))); } 但是我收到以下错误: java.lang.IllegalArgumentException: requestURI [/] does not start with contextPath [/api] 怎么了? 是否可以在代码中的单个位置指定contextPath,例如直接在构建器中? 编辑 在这里控制器 @RestController @RequestMapping(value = “/business-case”, produces = MediaType.APPLICATION_JSON_VALUE) public class […]