Spring 云合同存根 jar 作为 http 休息端点
Spring cloud contract stub jar as a http rest endpoint
我正在尝试将 Spring 合同存根 jar 设置为带有消费者的胖 jar 或我的服务可以向其发送请求并最终接收评估响应的 http REST 端点。
理想情况下,我更喜欢后者,其中消费者可以 运行 存根来管理交互。我从消费者到本地生产者存根的测试按预期工作。当我向存根 运行ner 的主 class 添加所需的注释时,我的编译失败了。我想我缺少消费者需要的一些配置或设置 运行 存根作为 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>
由于您正在尝试将测试代码添加到您的主要生产代码中,因此您必须更改
<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>
我正在尝试将 Spring 合同存根 jar 设置为带有消费者的胖 jar 或我的服务可以向其发送请求并最终接收评估响应的 http REST 端点。
理想情况下,我更喜欢后者,其中消费者可以 运行 存根来管理交互。我从消费者到本地生产者存根的测试按预期工作。当我向存根 运行ner 的主 class 添加所需的注释时,我的编译失败了。我想我缺少消费者需要的一些配置或设置 运行 存根作为 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>
由于您正在尝试将测试代码添加到您的主要生产代码中,因此您必须更改
<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>