2015年4月2日木曜日

[Spring]MockMVCとJsonPathをつかたテストでjava.lang.NoClassDefFoundError: com/jayway/jsonpath/InvalidPathExceptionが出た場合の対処


エラー内容

java.lang.NoClassDefFoundError: com/jayway/jsonpath/InvalidPathException
 at org.springframework.test.web.servlet.result.JsonPathResultMatchers.(JsonPathResultMatchers.java:44)
 at org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath

対処方法

依存ライブラリにjson-pathを追加します。

Gradleの場合には、以下のようになります。
    testCompile "com.jayway.jsonpath:json-path:2.0.0"