diff --git a/boot-ultimate-redis/src/test/java/com/example/ultimateredis/TestUltimateRedisApplication.java b/boot-ultimate-redis/src/test/java/com/example/ultimateredis/TestUltimateRedisApplication.java index ec04ff964..d73950076 100644 --- a/boot-ultimate-redis/src/test/java/com/example/ultimateredis/TestUltimateRedisApplication.java +++ b/boot-ultimate-redis/src/test/java/com/example/ultimateredis/TestUltimateRedisApplication.java @@ -4,6 +4,7 @@ import org.springframework.boot.test.context.TestConfiguration; import org.springframework.boot.testcontainers.service.connection.ServiceConnection; import org.springframework.context.annotation.Bean; +import org.springframework.test.context.DynamicPropertyRegistry; import org.testcontainers.containers.GenericContainer; import org.testcontainers.utility.DockerImageName; @@ -12,9 +13,13 @@ class TestUltimateRedisApplication { @Bean @ServiceConnection(name = "redis") - GenericContainer redisContainer() { - return new GenericContainer<>(DockerImageName.parse("redis").withTag("7.2.2-alpine")) - .withExposedPorts(6379); + GenericContainer redisContainer(DynamicPropertyRegistry dynamicPropertyRegistry) { + GenericContainer redisContiner = + new GenericContainer<>(DockerImageName.parse("redis").withTag("7.2.2-alpine")) + .withExposedPorts(6379); + dynamicPropertyRegistry.add("cache.redis-port", () -> redisContiner.getMappedPort(6379)); + dynamicPropertyRegistry.add("cache.redis-host", redisContiner::getHost); + return redisContiner; } public static void main(String[] args) {