Testing with Spring MockMvc and json-path “java.lang.NoClassDefFoundError: com/jayway/jsonpath/InvalidPathException”

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:



Problem solved!

  1. Ben said:

    Awesome! Thanks you solved my problem! BTW if someone is using gradle: compile(‘com.jayway.jsonpath:json-path:0.8.1’)

  2. Aman said:

    Thanks for the post.Spring boot 1.3 doesn’t work without this dependency, however spring boot 1.4 is working fine without adding this dependency.

  3. Thanks a bunch.

    By the way, if you’re using spring 4.1 you have you have to use version <= 0.9.1

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: