SpringCloud 提供固定端口
2023-12-11 17:14 更新
使用StubRunnerRule
或StubRunnerExtension
时,可以添加一个存根进行下载,然后将最后一个已下载存根的端口传递给该端口。
@ClassRule public static StubRunnerRule rule = new StubRunnerRule().repoRoot(repoRoot()) .stubsMode(StubRunnerProperties.StubsMode.REMOTE) .downloadStub("org.springframework.cloud.contract.verifier.stubs", "loanIssuance") .withPort(12345).downloadStub( "org.springframework.cloud.contract.verifier.stubs:fraudDetectionServer:12346"); @BeforeClass @AfterClass public static void setupProps() { System.clearProperty("stubrunner.repository.root"); System.clearProperty("stubrunner.classifier"); }
您可以看到对于此示例,以下测试有效:
then(rule.findStubUrl("loanIssuance")) .isEqualTo(URI.create("http://localhost:12345").toURL()); then(rule.findStubUrl("fraudDetectionServer")) .isEqualTo(URI.create("http://localhost:12346").toURL());
以上内容是否对您有帮助:
更多建议: