gpt4 book ai didi

java - 导入 org.springframework.test.context.junit4.SpringJUnit4ClassRunner 无法解析

转载 作者:IT老高 更新时间:2023-10-28 13:54:16 30 4
gpt4 key购买 nike

我是 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/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com