在我的情况下
有测试代码包含jsonPath用法:
mockMvc.perform(get("/api/userDetails").header("Authorization", base64ForTestUser).accept(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andDo(print())
.andExpect(jsonPath("userName").value("testUser"));
我得到了
java.lang.NoClassDefFoundError: com/jayway/jsonpath/InvalidPathException
和
java.lang.ClassNotFoundException: com.jayway.jsonpath.InvalidPathException
此错误是由于缺乏此类依赖关系直接引起的
<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path-assert</artifactId>
<version>0.8.1</version>
<scope>test</scope>
</dependency>