我在pom.xml下面构建spring-cloud-contract-verifier时遇到问题:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.10.RELEASE</version>
<relativePath />
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<docker-maven-plugin.version>1.2.0</docker-maven-plugin.version>
<spring-cloud.version>1.3.2.RELEASE</spring-cloud.version>
<geometry.version>2.11</geometry.version>
<mockito.version>1.9.5</mockito.version>
</properties>
<dependencies>
<!--############################################# SPRING ####################################################-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<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>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-cache</artifactId>
</dependency>
<dependency>
<groupId>org.ehcache</groupId>
<artifactId>ehcache</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-ehcache</artifactId>
<version>5.0.12.Final</version>
</dependency>
<dependency>
<groupId>javax.cache</groupId>
<artifactId>cache-api</artifactId>
</dependency>
<!--######################################### SPRING-CLOUD ##################################################-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-contract-verifier</artifactId>
<version>2.1.1.RELEASE</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-stream-test-support</artifactId>
<version>1.3.3.RELEASE</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.jayway.restassured</groupId>
<artifactId>spring-mock-mvc</artifactId>
<version>2.2.0</version>
<scope>test</scope>
</dependency>
<!--############################################## MYSQL ####################################################-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<!--############################################### GEO #####################################################-->
<dependency>
<groupId>com.jillesvangurp</groupId>
<artifactId>geogeometry</artifactId>
<version>${geometry.version}</version>
<exclusions>
<exclusion>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</exclusion>
</exclusions>
</dependency>
<!--############################################ MOCKITO ####################################################-->
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>
<!--##################################### END-OF-DEPENDENCIES ###############################################-->
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<executable>true</executable>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-contract-maven-plugin</artifactId>
<version>1.2.2.RELEASE</version>
<extensions>true</extensions>
<configuration>
<baseClassForTests>
com.foo.pricing.contract.BaseClass
</baseClassForTests>
</configuration>
</plugin>
</plugins>
</build>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.10.RELEASE</version>
<relativePath />
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<docker-maven-plugin.version>1.2.0</docker-maven-plugin.version>
<spring-cloud.version>1.3.2.RELEASE</spring-cloud.version>
<geometry.version>2.11</geometry.version>
<mockito.version>1.9.5</mockito.version>
</properties>
<dependencies>
<!--############################################# SPRING ####################################################-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<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>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-cache</artifactId>
</dependency>
<dependency>
<groupId>org.ehcache</groupId>
<artifactId>ehcache</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-ehcache</artifactId>
<version>5.0.12.Final</version>
</dependency>
<dependency>
<groupId>javax.cache</groupId>
<artifactId>cache-api</artifactId>
</dependency>
<!--######################################### SPRING-CLOUD ##################################################-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-contract-verifier</artifactId>
<version>2.1.1.RELEASE</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-stream-test-support</artifactId>
<version>1.3.3.RELEASE</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.jayway.restassured</groupId>
<artifactId>spring-mock-mvc</artifactId>
<version>2.2.0</version>
<scope>test</scope>
</dependency>
<!--############################################## MYSQL ####################################################-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<!--############################################### GEO #####################################################-->
<dependency>
<groupId>com.jillesvangurp</groupId>
<artifactId>geogeometry</artifactId>
<version>${geometry.version}</version>
<exclusions>
<exclusion>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</exclusion>
</exclusions>
</dependency>
<!--############################################ MOCKITO ####################################################-->
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>
<!--##################################### END-OF-DEPENDENCIES ###############################################-->
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<executable>true</executable>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-contract-maven-plugin</artifactId>
<version>1.2.2.RELEASE</version>
<extensions>true</extensions>
<configuration>
<baseClassForTests>
com.foo.pricing.contract.BaseClass
</baseClassForTests>
</configuration>
</plugin>
</plugins>
</build>
我尝试全新安装项目,以使我的测试类由spring-cloud-contract生成。
如下:
@RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.MOCK,类= PricingServiceApplication.class) @DirtiesContext 公共类BaseClass {
BaseClass
}
我偶然发现的异常如下:
@Autowired
private RateChartController rateChartController;
@Before
public void setup() {
StandaloneMockMvcBuilder standaloneMockMvcBuilder = MockMvcBuilders
.standaloneSetup(rateChartController);
RestAssuredMockMvc.standaloneSetup(standaloneMockMvcBuilder);
}
非常感谢您能帮助我解决此问题。
答案 0 :(得分:1)
经过几天的努力寻找解决方案后,我得出的结论是我的Spring Boot版本(1.5.10)与Spring Cloud Contract Verifier(2.1.1)不兼容,尽管我没有找到任何兼容性矩阵在网络上,在这种情况下,它只是基于我的实验。通过迁移到Spring Boot 2.1.x,此问题已得到解决,并且可以正常运行。非常感谢Josh Long和Marcin Grzejszczak在会议上关于Spring Contract的演讲。
答案 1 :(得分:1)
要针对该问题应用临时解决方案,只需在(src/test/resources
)下创建一个文件夹协定。创建后应该是({src/test/resources/contracts
)。
但是,您应该实施合同验证程序以相应地满足您的端点。希望对您有所帮助。
答案 2 :(得分:0)
看起来您在默认路径(src / test / resources / contracts)下没有合同,这导致不进行复制,然后将其定向到目标,从而导致异常。