I recently started a new Spring Boot project and was configuring my initial MockMvc Integration tests, and although I could happily static import jsonPath (via import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath) I was getting the following Exception when running what I thought should be a passing test:
java.lang.NoClassDefFoundError: com/jayway/jsonpath/InvalidPathException at org.springframework.test.web.servlet.result.JsonPathResultMatchers.<init>(JsonPathResultMatchers.java:43) at org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath(MockMvcResultMatchers.java:196)
It turns out that I was missing a dependency for the jsonPath library… I’m not sure why this isn’t included with the Spring Boot libraries, as most other things are?
Anyway, the fix was to simply add this to my pom:
<dependency> <groupId>com.jayway.jsonpath</groupId> <artifactId>json-path</artifactId> <scope>test</scope> </dependency>