在测试中SpringBootTest.WebEnvironment.RANDOM_端口时,如何访问local.server.port
我正在尝试在spring启动应用程序的测试中为Spock测试设置假客户端 Spock测试是用在测试中SpringBootTest.WebEnvironment.RANDOM_端口时,如何访问local.server.port,spring,spring-boot,spock,spring-cloud-feign,Spring,Spring Boot,Spock,Spring Cloud Feign,我正在尝试在spring启动应用程序的测试中为Spock测试设置假客户端 Spock测试是用 @ActiveProfiles("functional-test") @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) 我有一个application-functional-test.yml,其中我的假客户端是url define,我尝试了: my.feign.client.example.url:
@ActiveProfiles("functional-test")
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
我有一个application-functional-test.yml,其中我的假客户端是url define,我尝试了:
my.feign.client.example.url: localhost:${local.server.port}
但是本地服务器端口显示为0,这不适合应用程序的随机端口
我还尝试了在randomServerPort包含随机端口的情况下执行此操作,但我无法覆盖该属性:
@LocalServerPort
int randomServerPort;
@Value('${my.feign.client.example.url}')
String feignTestClient
void setup() {
feignTestClient="localhost:${randomServerPort}"
}
有什么好办法吗?我更喜欢在application-functional-test.yml中设置url,因此避免使用伪值初始化
我的假客户是这样的:
@FeignClient(name = "myClient", url = "${my.feign.client.example.url}")
public interface FeignTestRestClient extends SomeControllerApi {}