Skip to content

Commit

Permalink
Use @DynamicPropertySource in the Spring Boot example (#2495)
Browse files Browse the repository at this point in the history
  • Loading branch information
bsideup committed Mar 31, 2020
1 parent a51b1e0 commit 682bfac
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion examples/spring-boot/build.gradle
@@ -1,6 +1,6 @@
plugins {
id 'java'
id 'org.springframework.boot' version '2.2.5.RELEASE'
id 'org.springframework.boot' version '2.2.6.RELEASE'
}
apply plugin: 'io.spring.dependency-management'

Expand Down
Expand Up @@ -4,6 +4,8 @@
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.DynamicPropertyRegistry;
import org.springframework.test.context.DynamicPropertySource;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.testcontainers.containers.GenericContainer;

Expand All @@ -15,13 +17,13 @@
@ActiveProfiles("test")
public abstract class AbstractIntegrationTest {

static {
GenericContainer redis = new GenericContainer("redis:3-alpine")
.withExposedPorts(6379);
redis.start();

System.setProperty("spring.redis.host", redis.getContainerIpAddress());
System.setProperty("spring.redis.port", redis.getFirstMappedPort() + "");
static GenericContainer redis = new GenericContainer("redis:3-alpine")
.withExposedPorts(6379);

@DynamicPropertySource
static void redisProperties(DynamicPropertyRegistry registry) {
redis.start();
registry.add("spring.redis.host", redis::getContainerIpAddress);
registry.add("spring.redis.port", redis::getFirstMappedPort);
}
}

0 comments on commit 682bfac

Please sign in to comment.