스프링 부트 통합을 통해 무작위로 자유롭게 포트를 생성 할 수 있습니다. 그러나 나는 또한 Redis를위한 무료 포트가 필요합니다.스프링 부트 통합 테스트 무작위 무료 포트
@ContextConfiguration(classes = {MyApplication.class}, loader = SpringApplicationContextLoader.class)
@WebIntegrationTest(randomPort = true, value = "server.port:0")
@ActiveProfiles(profiles = {"local"})
public class SegmentSteps {
private static final String HOST_TEMPLATE = "http://localhost:%s";
// Needs to be a random open port
private static final int REDIS_PORT = 6380;
private String host;
@Value("${local.server.port}")
private int serverPort;
private RedisServer redisServer;
@Before
public void beforeScenario() throws Exception {
host = String.format(HOST_TEMPLATE, serverPort);
redisServer = RedisServer.builder()
.redisExecProvider(RedisExecProvider.defaultProvider())
.port(REDIS_PORT)
.setting("bind 127.0.0.1")
.build();
redisServer.start();
}
...
}
어떻게해야합니까?
인가 문맥 안에 동일한 수를 얻는 방법 있는가? – ptimson
아니면 그냥 int bean을 사용합니까? 한정어로? – ptimson
@ptimson, 귀하의 질문에 이해가되지 않습니다. 당신은 정교 할 수 있습니까? – mre