From b82460f33c88d05ecd4b279df7fe816c3fb8b4fa Mon Sep 17 00:00:00 2001 From: Christoph Strobl Date: Tue, 5 Apr 2016 17:39:59 +0200 Subject: [PATCH] #158 - Remove workaround for Redis cluster configuration. SpringBoot 1.4M1 ships with auto configuration for spring.redis.cluster so we removed the work around using ConfigurationProperties. --- redis/cluster/readme.md | 36 +------------- .../springdata/redis/cluster/AppConfig.java | 35 +------------- .../ClusterConfigurationProperties.java | 47 ------------------- 3 files changed, 3 insertions(+), 115 deletions(-) delete mode 100644 redis/cluster/src/main/java/example/springdata/redis/cluster/ClusterConfigurationProperties.java diff --git a/redis/cluster/readme.md b/redis/cluster/readme.md index f463eb35..8ef68430 100644 --- a/redis/cluster/readme.md +++ b/redis/cluster/readme.md @@ -6,7 +6,7 @@ To run the code in this sample a running cluster environment is required. Please ## Support for Cluster ## -Cluster Support uses the same building blocks as the non clustered counterpart. We use `application.properties` to point to an initial set of known cluster nodes. +Cluster Support uses the same building blocks as the non clustered counterpart. We use `application.properties` to point to an initial set of known cluster nodes which will be picked up by the auto configuration. ```properties spring.redis.cluster.nodes[0]=127.0.0.1:30001 @@ -14,40 +14,6 @@ spring.redis.cluster.nodes[1]=127.0.0.1:30002 spring.redis.cluster.nodes[2]=127.0.0.1:30003 ``` -Additionally we need to have the `RedisConnectionFactory` set up with the according `RedisClusterConfiguration`. - -```java -@Configuration -@EnableConfigurationProperties(ClusterConfigurationProperties.class) -public class AppConfig { - - /** - * Type safe representation of application.properties - */ - @Autowired ClusterConfigurationProperties clusterProperties; - - /** - * The connection factory used for obtaining RedisConnection - * uses a RedisClusterConfiguration that points - * to the initial set of nodes. - */ - @Bean - RedisConnectionFactory connectionFactory() { - return new JedisConnectionFactory( - new RedisClusterConfiguration(clusterProperties.getNodes())); - } - - /** - * RedisTemplate can be configured with RedisSerializer if needed. - * NOTE: be careful using JSON serializers for key serialization. - */ - @Bean - RedisTemplate redisTemplate() { - return new StringRedisTemplate(connectionFactory()); - } -} -``` - **INFORMATION:** The tests flush the db of all known instances during the JUnit _setup_ phase to allow inspecting data directly on the cluster nodes after a test is run. ## Cluster Setup ## diff --git a/redis/cluster/src/main/java/example/springdata/redis/cluster/AppConfig.java b/redis/cluster/src/main/java/example/springdata/redis/cluster/AppConfig.java index 80a910c5..078970a0 100644 --- a/redis/cluster/src/main/java/example/springdata/redis/cluster/AppConfig.java +++ b/redis/cluster/src/main/java/example/springdata/redis/cluster/AppConfig.java @@ -15,17 +15,9 @@ */ package example.springdata.redis.cluster; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.data.redis.connection.RedisClusterConfiguration; -import org.springframework.data.redis.connection.RedisConnection; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.data.redis.connection.RedisConnectionFactory; -import org.springframework.data.redis.connection.jedis.JedisConnectionFactory; import org.springframework.data.redis.core.RedisTemplate; -import org.springframework.data.redis.core.StringRedisTemplate; -import org.springframework.data.redis.serializer.RedisSerializer; /** * Application context configuration setting up {@link RedisConnectionFactory} and {@link RedisTemplate} according to @@ -33,30 +25,7 @@ import org.springframework.data.redis.serializer.RedisSerializer; * * @author Christoph Strobl */ -@Configuration -@EnableConfigurationProperties(ClusterConfigurationProperties.class) +@EnableAutoConfiguration public class AppConfig { - /** - * Type safe representation of application.properties - */ - @Autowired ClusterConfigurationProperties clusterProperties; - - /** - * The connection factory used for obtaining {@link RedisConnection} uses a {@link RedisClusterConfiguration} that - * points to the initial set of nodes. - */ - @Bean - RedisConnectionFactory connectionFactory() { - return new JedisConnectionFactory(new RedisClusterConfiguration(clusterProperties.getNodes())); - } - - /** - * {@link RedisTemplate} can be configured with {@link RedisSerializer} if needed.
- * NOTE: be careful using JSON @link RedisSerializer} for key serialization. - */ - @Bean - RedisTemplate redisTemplate() { - return new StringRedisTemplate(connectionFactory()); - } } diff --git a/redis/cluster/src/main/java/example/springdata/redis/cluster/ClusterConfigurationProperties.java b/redis/cluster/src/main/java/example/springdata/redis/cluster/ClusterConfigurationProperties.java deleted file mode 100644 index 29044d82..00000000 --- a/redis/cluster/src/main/java/example/springdata/redis/cluster/ClusterConfigurationProperties.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright 2015-2016 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package example.springdata.redis.cluster; - -import java.util.List; - -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.stereotype.Component; - -/** - * Type safe representation of {@code spring.redis.cluster.*} properties in {@literal application.properties}. - * - * @author Christoph Strobl - * @author Oliver Gierke - */ -@Component -@ConfigurationProperties(prefix = "spring.redis.cluster") -public class ClusterConfigurationProperties { - - private List nodes; - - /** - * Get initial collection of known cluster nodes in format {@code host:port}. - * - * @return - */ - public List getNodes() { - return nodes; - } - - public void setNodes(List nodes) { - this.nodes = nodes; - } -}