File tree Expand file tree Collapse file tree 2 files changed +13
-7
lines changed
framework-docs/src/docs/asciidoc/testing
spring-test/src/main/java/org/springframework/test/context Expand file tree Collapse file tree 2 files changed +13
-7
lines changed Original file line number Diff line number Diff line change @@ -2022,12 +2022,14 @@ properties.
20222022 class ExampleIntegrationTests {
20232023
20242024 @Container
2025- static RedisContainer redis = new RedisContainer();
2025+ static GenericContainer redis =
2026+ new GenericContainer(DockerImageName.parse("redis:5.0.3-alpine"))
2027+ .withExposedPorts(6379);
20262028
20272029 @DynamicPropertySource
20282030 static void redisProperties(DynamicPropertyRegistry registry) {
20292031 registry.add("redis.host", redis::getHost);
2030- registry.add("redis.port", redis::getMappedPort );
2032+ registry.add("redis.port", redis::getFirstMappedPort );
20312033 }
20322034
20332035 // tests ...
@@ -2045,13 +2047,15 @@ properties.
20452047
20462048 @Container
20472049 @JvmStatic
2048- val redis: RedisContainer = RedisContainer()
2050+ val redis: GenericContainer =
2051+ GenericContainer(DockerImageName.parse("redis:5.0.3-alpine"))
2052+ .withExposedPorts(6379)
20492053
20502054 @DynamicPropertySource
20512055 @JvmStatic
20522056 fun redisProperties(registry: DynamicPropertyRegistry) {
20532057 registry.add("redis.host", redis::getHost)
2054- registry.add("redis.port", redis::getMappedPort )
2058+ registry.add("redis.port", redis::getFirstMappedPort )
20552059 }
20562060 }
20572061
Original file line number Diff line number Diff line change 11/*
2- * Copyright 2002-2022 the original author or authors.
2+ * Copyright 2002-2023 the original author or authors.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
7070 * class ExampleIntegrationTests {
7171 *
7272 * @Container
73- * static RedisContainer redis = new RedisContainer();
73+ * static GenericContainer redis =
74+ * new GenericContainer(DockerImageName.parse("redis:5.0.3-alpine"))
75+ * .withExposedPorts(6379);
7476 *
7577 * // ...
7678 *
7779 * @DynamicPropertySource
7880 * static void redisProperties(DynamicPropertyRegistry registry) {
7981 * registry.add("redis.host", redis::getHost);
80- * registry.add("redis.port", redis::getMappedPort );
82+ * registry.add("redis.port", redis::getFirstMappedPort );
8183 * }
8284 *
8385 * }</pre>
You can’t perform that action at this time.
0 commit comments