java - 导入 org.springframework.test.context.junit4.

我是 Spring 的新手,这也是我在 StackOverflow 上的第一个问题,所以我会尽量让这个问题易于理解。

我正在尝试在 this 上使用 Spring 和 Maven 创建 Web 服务客户端教程:我收到此错误:无法解析导入 org.springframework.test.context.junit4

这是我的代码:

package demo;

import hello.WsClientApplication;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; //this won't import


@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = WsClientApplication.class)
public class WsClientApplicationTests {

    @Test
    public void contextLoads() {
    }

}

这是我的 pom.xml,以备不时之需。

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.springframework</groupId>
    <artifactId>gs-consuming-web-service</artifactId>
    <version>0.1.0</version>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.2.3.RELEASE</version>
    </parent>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>
           <dependency>
               <groupId>org.springframework.ws</groupId>
               <artifactId>spring-ws-core</artifactId>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <!-- tag::wsdl[] -->
            <plugin>
                <groupId>org.jvnet.jaxb2.maven2</groupId>
                <artifactId>maven-jaxb2-plugin</artifactId>
                <version>0.12.3</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <schemaLanguage>WSDL</schemaLanguage>
                    <generatePackage>hello.wsdl</generatePackage>
                    <schemas>
                        <schema>
                            <url>http://wsf.cdyne.com/WeatherWS/Weather.asmx?wsdl</url>
                        </schema>
                    </schemas>
                </configuration>
            </plugin>
            <!-- end::wsdl[] -->
        </plugins>
    </build>

</project>

我在 StackOverflow 中尝试了其他一些解决方案,但无法正常工作。

谢谢。

最佳答案

需要在spring-boot-starter-test上添加一个依赖:

<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-test</artifactId>
  <scope>test</scope>
</dependency>

关于java - 导入 org.springframework.test.context.junit4.SpringJUnit4ClassRunner 无法解析,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30513375/

相关文章:

java - Spring批处理远程分块和远程分区之间的区别

spring - JPA 标准构建器中的忽略大小写

java - Spring jsp页面未评估

Java/Hibernate - 只读模式下不允许写操作

java - Spring 转换服务 - 从 List 到 List

spring - memcached 中的最大 key 长度和最大值大小是多少?

spring - 如何正确设置速度的加载器路径

java - 在 Spring 注解中使用静态变量

json - 如何解决 jackson 中属性(property)的 setter/getter 定

java - cvc-complex-type.2.4.c : The matching wildc