我尝试将以下合同依赖项用于合同消费者方测试:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-contract-stub-runner</artifactId>
<version>2.0.1.RELEASE</version>
<scope>test</scope>
</dependency>
在pom.xml文件中,我包括以下依赖项,并且该依赖项在.m2 / repository中可用:
<dependency>
<groupId>resmed</groupId>
<artifactId>pds-service</artifactId>
<version>0.0.1-SNAPSHOT-1</version>
<classifier>stubs</classifier>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
这是春季合同测试配置:
@RunWith(SpringRunner.class)
@SpringBootTest(classes = SpringBootApplication.class)
@AutoConfigureJsonTesters
@AutoConfigureStubRunner(ids = "mycompany:pds-service:+:stubs:8360")
@DirtiesContext
但是我遇到以下异常:
Caused by: java.lang.IllegalStateException: No stubs were found on classpath for [mycompany:pds-service]
at org.springframework.cloud.contract.stubrunner.ClasspathStubProvider$1.downloadAndUnpackStubJar(ClasspathStubProvider.java:99)
at org.springframework.cloud.contract.stubrunner.CompositeStubDownloader.downloadAndUnpackStubJar(CompositeStubDownloaderBuilder.java:80)
at org.springframework.cloud.contract.stubrunner.StubRunnerFactory.createStubsFromServiceConfiguration(StubRunnerFactory.java:66)
at org.springframework.cloud.contract.stubrunner.BatchStubRunnerFactory.buildBatchStubRunner(BatchStubRunnerFactory.java:69)
at org.springframework.cloud.contract.stubrunner.spring.StubRunnerConfiguration.batchStubRunner(StubRunnerConfiguration.java:84)
at org.springframework.cloud.contract.stubrunner.spring.StubRunnerConfiguration$$EnhancerBySpringCGLIB$$113b6f08.CGLIB$batchStubRunner$0(<generated>)
at org.springframework.cloud.contract.stubrunner.spring.StubRunnerConfiguration$$EnhancerBySpringCGLIB$$113b6f08$$FastClassBySpringCGLIB$$123beb15.invoke(<generated>) at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244)
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:363)
at org.springframework.cloud.contract.stubrunner.spring.StubRunnerConfiguration$$EnhancerBySpringCGLIB$$113b6f08.batchStubRunner(<generated>)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154)
... 74 more
如果我使用stubsMode = StubRunnerProperties.StubsMode.LOCAL,则一切正常(使用生产者本地版本)。但是我必须使用nexus的版本,因此本地模式无济于事。
问题似乎是存根运行程序没有从.m2 / repository中获取存根jar,该maven是在构建过程中从nexus下载的。
有人可以根据以上信息提供帮助吗?此类似的代码适用于1.2.1.Release。而且我检查了以下链接,但没有帮助。
https://github.com/spring-cloud/spring-cloud-contract/wiki/Spring-Cloud-Contract-2.0-Migration-Guide