【问题标题】:Spring cloud contract stub jar as a http rest endpointSpring Cloud 合约存根 jar 作为 http REST 端点
【发布时间】:2019-08-26 22:11:08
【问题描述】:

我正在尝试将 Spring 合同存根 jar 设置为带有使用者的胖 jar 或我的服务可以向其发送请求并最终接收评估响应的 http REST 端点。

理想情况下,我更喜欢后者,消费者可以运行存根来管理交互。我从消费者到本地生产者存根的测试按预期工作。当我将所需的注释添加到存根运行器的主类时,我的编译失败。我认为我缺少消费者将存根作为 http REST 端点运行或在其 m2 中识别所需的一些配置或设置。

应用程序编译失败,@EnableStubRunnerServer 抱怨以下内容:

ConsumerApplication.java:[8,60] package org.springframework.cloud.contract.stubrunner.server does not exist
ConsumerApplication.java:[15,2] cannot find symbol
[ERROR] symbol: class EnableStubRunnerServer

ConsumerApplication.java:

@SpringBootApplication
@EnableWebMvc
@EnableStubRunnerServer
@Slf4j

public class ConsumerApplication {
    public static void main(String[] args) {
        SpringApplication.run(ConsumerApplication.class, args);
    }
}

application.properties(消费者):

stubrunner.ids=com.somecompany.somegroup:producer:0.0.1-SNAPSHOT:stubs:8081
stubrunner.stubsMode=REMOTE
server.ssl.key-store-password=password
server.ssl.key-password=password
server.ssl.trust-store-password=password
server.port=8081

Test.java: - 这个测试有效

@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.MOCK)
@AutoConfigureMockMvc
@AutoConfigureJsonTesters
@AutoConfigureStubRunner( ids = "com.somecompany.somegroup:producer:+:stubs:8081", 
    stubsMode = StubRunnerProperties.StubsMode.LOCAL)
@DirtiesContext
public class ContractControllerTest extends AbstractTest {

}

pom:

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-contract-stub-runner</artifactId>
    <scope>test</scope>
</dependency>

【问题讨论】:

    标签: docker spring-cloud-contract


    【解决方案1】:

    由于您尝试将测试代码添加到主生产代码中,因此您必须进行更改

    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-contract-stub-runner</artifactId>
        <scope>test</scope>
    </dependency>
    

    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-contract-stub-runner</artifactId>
    </dependency>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-06-03
      • 1970-01-01
      • 2017-07-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-02
      • 1970-01-01
      相关资源
      最近更新 更多