Skip to content

Commit

Permalink
#755 - fixes issue with starting testcontainer in dev mode
Browse files Browse the repository at this point in the history
  • Loading branch information
rajadilipkolli committed Oct 22, 2023
1 parent 9042f91 commit 4c46b2f
Showing 1 changed file with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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) {
Expand Down

0 comments on commit 4c46b2f

Please sign in to comment.