java Spring 3.2 测试,com.jajway 不包含在依赖项中

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14005169/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 14:42:55  来源:igfitidea点击:

Spring 3.2 Test, com.jajway not included as dependency

javajsonspringspring-mvc

提问by NimChimpsky

My tests were failing because of a class not found exception on

我的测试失败,因为一个类未找到异常

import com.jayway.jsonpath.InvalidPathException;

import com.jayway.jsonpath.InvalidPathException;

within

在里面

org.springframework.test.util.JsonPathExpectationsHelper;

Manually adding the jayway dependency to my maven pom removed this error and my test ran as expected.

手动将 jayway 依赖项添加到我的 maven pom 消除了这个错误,我的测试按预期运行。

Have I found a bug, or do I need to add a different spring jar as well as spring test ?

我是否发现了错误,或者我是否需要添加不同的弹簧罐以及弹簧测试?

采纳答案by izilotti

External dependencies (e.g., JUnit, Mockito, Easy Mock, JayWay, etc.) are not included in Spring, so it is necessary to explicitly add them (Ant/Maven/Ivy dependency, or jar files) to the project's classpath.

Spring 中不包含外部依赖项(例如,JUnit、Mockito、Easy Mock、JayWay 等),因此需要将它们(Ant/Maven/Ivy 依赖项,或 jar 文件)显式添加到项目的类路径中。

回答by pbaranski

In my case

就我而言

Having test code what contained jsonPathusage:

具有包含jsonPath用法的测试代码:

 mockMvc.perform(get("/api/userDetails").header("Authorization", base64ForTestUser).accept(MediaType.APPLICATION_JSON))
                .andExpect(status().isOk())
                .andDo(print())
                .andExpect(jsonPath("userName").value("testUser"));

I was getting

我得到

java.lang.NoClassDefFoundError: com/jayway/jsonpath/InvalidPathException

and

java.lang.ClassNotFoundException: com.jayway.jsonpath.InvalidPathException

This error was directly caused by lack of such dependencies

这个错误是因为缺少这样的依赖直接导致的

<dependency>
    <groupId>com.jayway.jsonpath</groupId>
    <artifactId>json-path-assert</artifactId>
    <version>0.8.1</version>
    <scope>test</scope>
</dependency>

回答by Harsh Gupta

Adding this dependency worked

添加此依赖项有效

<dependency>
    <groupId>com.jayway.jsonpath</groupId>
    <artifactId>json-path-assert</artifactId>
    <version>0.8.1</version>
    <scope>test</scope>
</dependency>

If you want to use another version of json-path-assert you can review the following repository:

如果您想使用另一个版本的 json-path-assert,您可以查看以下存储库:

http://mvnrepository.com/artifact/com.jayway.jsonpath/json-path

http://mvnrepository.com/artifact/com.jayway.jsonpath/json-path