java 找不到 SpringRunner 依赖类
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/39074213/
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
SpringRunner dependency Class couldn't be located
提问by Sagar
I couldn't find which jar will provide me the dependency of SpringRunner.class
我找不到哪个 jar 会为我提供依赖 SpringRunner.class
I am trying to upgrade my Integration tests to spring-boot 1.4.0
我正在尝试将我的集成测试升级到 spring-boot 1.4.0
回答by Behrang Saeedzadeh
SpringRunner.java
is located in the spring-test-4.3.2.RELEASE.jar
file.
SpringRunner.java
位于spring-test-4.3.2.RELEASE.jar
文件中。
In order to use it in a Maven or Gradle project, you should declare a dependency on org.springframework.boot:spring-boot-starter-test
.
为了在 Maven 或 Gradle 项目中使用它,您应该声明对org.springframework.boot:spring-boot-starter-test
.
Here are the libraries that org.springframework.boot:spring-boot-starter-test
depends on:
以下是org.springframework.boot:spring-boot-starter-test
依赖的库:
+--- org.springframework.boot:spring-boot-starter-test: -> 1.4.0.RELEASE
| +--- org.springframework.boot:spring-boot-test:1.4.0.RELEASE
| | \--- org.springframework.boot:spring-boot:1.4.0.RELEASE (*)
| +--- org.springframework.boot:spring-boot-test-autoconfigure:1.4.0.RELEASE
| | +--- org.springframework.boot:spring-boot-test:1.4.0.RELEASE (*)
| | \--- org.springframework.boot:spring-boot-autoconfigure:1.4.0.RELEASE (*)
| +--- com.jayway.jsonpath:json-path:2.2.0
| | +--- net.minidev:json-smart:2.2.1
| | | \--- net.minidev:accessors-smart:1.1
| | | \--- org.ow2.asm:asm:5.0.3
| | \--- org.slf4j:slf4j-api:1.7.16 -> 1.7.19
| +--- junit:junit:4.12
| | \--- org.hamcrest:hamcrest-core:1.3
| +--- org.assertj:assertj-core:2.5.0 -> 2.4.1
| +--- org.mockito:mockito-core:1.10.19
| | +--- org.hamcrest:hamcrest-core:1.1 -> 1.3
| | \--- org.objenesis:objenesis:2.1 -> 2.2
| +--- org.hamcrest:hamcrest-core:1.3
| +--- org.hamcrest:hamcrest-library:1.3
| | \--- org.hamcrest:hamcrest-core:1.3
| +--- org.skyscreamer:jsonassert:1.3.0
| | \--- org.json:json:20090211 -> 20140107
| +--- org.springframework:spring-core:4.3.2.RELEASE
| \--- org.springframework:spring-test:4.3.2.RELEASE
| \--- org.springframework:spring-core:4.3.2.RELEASE
回答by Mark Mueller
Try manually adding this import:
尝试手动添加此导入:
import org.springframework.test.context.junit4.SpringRunner;
导入 org.springframework.test.context.junit4.SpringRunner;
回答by Tobias Otto
You could search for a class in search.maven.org
你可以在 search.maven.org 中搜索一个类
https://search.maven.org/#search|ga|1|fc%3A%22SpringRunner%22
https://search.maven.org/#search|ga|1|fc%3A%22SpringRunner%22
回答by abaghel
Use following maven dependencies.
使用以下 Maven 依赖项。
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.0.RELEASE</version>
<relativePath />
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
回答by Sameer
Download the Spring-test jar and add it manually to the build path by adding external jars. It resolved all the problem for me.
下载 Spring-test jar 并通过添加外部 jar 将其手动添加到构建路径。它为我解决了所有问题。
::Download jar from here: https://mvnrepository.com/artifact/org.springframework/spring-test/2.5
::从这里下载 jar:https: //mvnrepository.com/artifact/org.springframework/spring-test/2.5
回答by Ahmed Saad
upgrade spring-boot-starter-parent to 2.0.1.RELEASE
将 spring-boot-starter-parent 升级到 2.0.1.RELEASE
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.1.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->