为什么我的班级找不到“ContractVerifierUtil"? [英] Why can't my class find "ContractVerifierUtil"?

查看:39
本文介绍了为什么我的班级找不到“ContractVerifierUtil"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的项目中实现存根,但是当我尝试构建它时出现以下错误:

I am trying to implement stubs in my project but I am getting the follwing error when I try to build it:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:testCompile (default-testCompile) on project customer-previous-address-older-version: Compilation failure
[ERROR] /archive/target/generated-test-sources/contracts/address/ContractVerifierTest.java:[18,63] cannot find symbol
[ERROR]   symbol:   class ContractVerifierUtil
[ERROR]   location: package org.springframework.cloud.contract.verifier.util

由于发生错误的代码是自动生成的,我不确定我能做什么.

Since the code that the error is occurring is auto-generated, I'm not sure exactly what I can do.

这是自动生成的测试类:

This is the test class that is being auto-generated:

package ie.aib.customer.address;

import com.jayway.jsonpath.DocumentContext;
import com.jayway.jsonpath.JsonPath;
import PreviousAddressBaseTest;
import io.restassured.module.mockmvc.specification.MockMvcRequestSpecification;
import io.restassured.response.ResponseOptions;
import java.io.StringReader;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.junit.Test;
import org.w3c.dom.Document;
import org.xml.sax.InputSource;

import static com.toomuchcoding.jsonassert.JsonAssertion.assertThatJson;
import static io.restassured.module.mockmvc.RestAssuredMockMvc.*;
import static org.springframework.cloud.contract.verifier.assertion.SpringCloudContractAssertions.assertThat;
import static org.springframework.cloud.contract.verifier.util.ContractVerifierUtil.*;

public class ContractVerifierTest extends PreviousAddressBaseTest {

    @Test
    public void validate_shouldReturnPreviousAddress() throws Exception {
        // given:
            MockMvcRequestSpecification request = given();

        // when:
            ResponseOptions response = given().spec(request)
                    .get("/previous-address");

        // then:
            assertThat(response.statusCode()).isEqualTo(200);
            assertThat(response.header("Content-Type")).matches("text/plain;charset=ISO-8859-1");
        // and:
            String responseBody = response.getBody().asString();
            assertThat(responseBody).isEqualTo("Send me something!");
    }

}

我添加了以下依赖项,我认为这可以解决问题,但没有:

I added the following dependancy, which I thought would fix the problem, but it hasn't:

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-contract-verifier</artifactId>
</dependency>

推荐答案

尝试在我们的 Maven POM 部分添加 spring-cloud-dependencies.还要确保 spring-cloud.version 在任何地方都相同,包括依赖 spring-cloud-contract-verifier,因为我因此遇到了这个错误.

Try adding spring-cloud-dependencies in the section of our Maven POM. Also make sure spring-cloud.version same everywhere, including for dependency spring-cloud-contract-verifier because i had faced this error due to this.

<dependencyManagement>
   <dependencies>
      <dependency>
         <groupId>org.springframework.cloud</groupId>
         <artifactId>spring-cloud-dependencies</artifactId>
         <version>${spring-cloud.version}</version>
         <type>pom</type>
         <scope>import</scope>
      </dependency>
   </dependencies>
</dependencyManagement>

这篇关于为什么我的班级找不到“ContractVerifierUtil"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆