diff --git a/build.gradle b/build.gradle index 8f4270d0..bfe8e7e1 100644 --- a/build.gradle +++ b/build.gradle @@ -40,7 +40,9 @@ jar { dependencies { compile('org.springframework.boot:spring-boot-starter-web') compile('org.springframework.boot:spring-boot-starter-data-jpa') - compile('org.springframework.boot:spring-boot-starter-data-redis') + compile('org.springframework.boot:spring-boot-starter-data-redis') { + exclude module: 'jedis' + } compile('org.springframework.boot:spring-boot-starter-thymeleaf') compile('org.springframework.boot:spring-boot-starter-security') compile('org.springframework.boot:spring-boot-actuator') @@ -57,6 +59,7 @@ dependencies { compile('org.projectlombok:lombok:1.16.8') compile('org.flywaydb:flyway-core:4.0') compile('mysql:mysql-connector-java:5.1.38') + compile('biz.paluch.redis:lettuce:3.5.0.Final') testCompile('org.springframework.boot:spring-boot-configuration-processor') testCompile('org.springframework.boot:spring-boot-devtools') testCompile('org.springframework.security:spring-security-test') diff --git a/src/main/java/io/pivotal/cla/config/SessionConfig.java b/src/main/java/io/pivotal/cla/config/SessionConfig.java index 4b5befbc..4d5572eb 100644 --- a/src/main/java/io/pivotal/cla/config/SessionConfig.java +++ b/src/main/java/io/pivotal/cla/config/SessionConfig.java @@ -16,24 +16,48 @@ package io.pivotal.cla.config; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.boot.autoconfigure.data.redis.RedisProperties; +import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.cloud.Cloud; import org.springframework.cloud.CloudFactory; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Profile; import org.springframework.data.redis.connection.RedisConnectionFactory; +import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; /** * @author Mark Paluch */ @Configuration +@EnableConfigurationProperties(RedisProperties.class) public class SessionConfig { @Profile(GitHubClaProfiles.CLOUDFOUNDRY) @Bean - public RedisConnectionFactory redisConnectionFactory() { + public RedisConnectionFactory cloudRedisConnectionFactory() { CloudFactory cloudFactory = new CloudFactory(); Cloud cloud = cloudFactory.getCloud(); - return cloud.getSingletonServiceConnector(RedisConnectionFactory.class, null); + RedisConnectionFactory connectionFactory = cloud.getSingletonServiceConnector(RedisConnectionFactory.class, null); + + if(connectionFactory instanceof LettuceConnectionFactory){ + ((LettuceConnectionFactory) connectionFactory).setShutdownTimeout(0); + } + + return connectionFactory; + } + + @Bean + @ConditionalOnMissingBean(RedisConnectionFactory.class) + public RedisConnectionFactory redisConnectionFactory(RedisProperties redisProperties) { + + LettuceConnectionFactory connectionFactory = new LettuceConnectionFactory(); + connectionFactory.setPort(redisProperties.getPort()); + connectionFactory.setHostName(redisProperties.getHost()); + connectionFactory.setPassword(redisProperties.getPassword()); + connectionFactory.setShutdownTimeout(0); + + return connectionFactory; } }