|
15 | 15 | */
|
16 | 16 | package example.springdata.redis;
|
17 | 17 |
|
18 |
| -import jakarta.annotation.PreDestroy; |
19 |
| - |
| 18 | +import com.redis.testcontainers.RedisContainer; |
20 | 19 | import org.springframework.boot.autoconfigure.SpringBootApplication;
|
| 20 | +import org.springframework.boot.testcontainers.service.connection.ServiceConnection; |
21 | 21 | import org.springframework.context.annotation.Bean;
|
22 | 22 | import org.springframework.data.redis.connection.ReactiveRedisConnectionFactory;
|
23 |
| -import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; |
24 | 23 | import org.springframework.data.redis.core.ReactiveRedisTemplate;
|
25 | 24 | import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
|
26 | 25 | import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
|
27 | 26 | import org.springframework.data.redis.serializer.RedisSerializationContext;
|
28 | 27 | import org.springframework.data.redis.serializer.RedisSerializationContext.RedisSerializationContextBuilder;
|
29 | 28 | import org.springframework.data.redis.serializer.StringRedisSerializer;
|
| 29 | +import org.testcontainers.utility.DockerImageName; |
30 | 30 |
|
31 | 31 | /**
|
32 | 32 | * @author Mark Paluch
|
| 33 | + * @author Christoph Strobl |
33 | 34 | */
|
34 | 35 | @SpringBootApplication
|
35 | 36 | public class RedisTestConfiguration {
|
36 | 37 |
|
37 | 38 | @Bean
|
38 |
| - public LettuceConnectionFactory redisConnectionFactory() { |
39 |
| - return new LettuceConnectionFactory(); |
| 39 | + @ServiceConnection(name = "redis") |
| 40 | + RedisContainer redisContainer() { |
| 41 | + return new RedisContainer(DockerImageName.parse("redis:7")); |
40 | 42 | }
|
41 | 43 |
|
42 | 44 | /**
|
@@ -72,10 +74,4 @@ public ReactiveRedisTemplate<String, Object> reactiveJsonObjectRedisTemplate(
|
72 | 74 | return new ReactiveRedisTemplate<>(connectionFactory, serializationContext);
|
73 | 75 | }
|
74 | 76 |
|
75 |
| - /** |
76 |
| - * Clear database before shut down. |
77 |
| - */ |
78 |
| - public @PreDestroy void flushTestDb() { |
79 |
| - redisConnectionFactory().getConnection().flushDb(); |
80 |
| - } |
81 | 77 | }
|
0 commit comments