|
15 | 15 | */
|
16 | 16 | package example.springdata.redis.cluster;
|
17 | 17 |
|
18 |
| -import org.springframework.beans.factory.annotation.Autowired; |
19 |
| -import org.springframework.boot.context.properties.EnableConfigurationProperties; |
20 |
| -import org.springframework.context.annotation.Bean; |
21 |
| -import org.springframework.context.annotation.Configuration; |
22 |
| -import org.springframework.data.redis.connection.RedisClusterConfiguration; |
23 |
| -import org.springframework.data.redis.connection.RedisConnection; |
| 18 | +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; |
24 | 19 | import org.springframework.data.redis.connection.RedisConnectionFactory;
|
25 |
| -import org.springframework.data.redis.connection.jedis.JedisConnectionFactory; |
26 | 20 | import org.springframework.data.redis.core.RedisTemplate;
|
27 |
| -import org.springframework.data.redis.core.StringRedisTemplate; |
28 |
| -import org.springframework.data.redis.serializer.RedisSerializer; |
29 | 21 |
|
30 | 22 | /**
|
31 | 23 | * Application context configuration setting up {@link RedisConnectionFactory} and {@link RedisTemplate} according to
|
32 | 24 | * {@link ClusterConfigurationProperties}.
|
33 | 25 | *
|
34 | 26 | * @author Christoph Strobl
|
35 | 27 | */
|
36 |
| -@Configuration |
37 |
| -@EnableConfigurationProperties(ClusterConfigurationProperties.class) |
| 28 | +@EnableAutoConfiguration |
38 | 29 | public class AppConfig {
|
39 | 30 |
|
40 |
| - /** |
41 |
| - * Type safe representation of application.properties |
42 |
| - */ |
43 |
| - @Autowired ClusterConfigurationProperties clusterProperties; |
44 |
| - |
45 |
| - /** |
46 |
| - * The connection factory used for obtaining {@link RedisConnection} uses a {@link RedisClusterConfiguration} that |
47 |
| - * points to the initial set of nodes. |
48 |
| - */ |
49 |
| - @Bean |
50 |
| - RedisConnectionFactory connectionFactory() { |
51 |
| - return new JedisConnectionFactory(new RedisClusterConfiguration(clusterProperties.getNodes())); |
52 |
| - } |
53 |
| - |
54 |
| - /** |
55 |
| - * {@link RedisTemplate} can be configured with {@link RedisSerializer} if needed. <br /> |
56 |
| - * <b>NOTE:</b> be careful using JSON @link RedisSerializer} for key serialization. |
57 |
| - */ |
58 |
| - @Bean |
59 |
| - RedisTemplate<String, String> redisTemplate() { |
60 |
| - return new StringRedisTemplate(connectionFactory()); |
61 |
| - } |
62 | 31 | }
|
0 commit comments