SpringCloud 提供固定端口

2023-12-11 17:14 更新

使用StubRunnerRuleStubRunnerExtension時(shí),可以添加一個(gè)存根進(jìn)行下載,然后將最后一個(gè)已下載存根的端口傳遞給該端口。

@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");
}

您可以看到對(duì)于此示例,以下測(cè)試有效:

then(rule.findStubUrl("loanIssuance"))
		.isEqualTo(URI.create("http://localhost:12345").toURL());
then(rule.findStubUrl("fraudDetectionServer"))
		.isEqualTo(URI.create("http://localhost:12346").toURL());
以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)