Fix RedisAutoConfiguration with pool config

fixes #850
pull/874/head
Christian Dupuis 11 years ago
parent b38601a2f2
commit d8ec2719d7

@ -42,6 +42,7 @@ import redis.clients.jedis.JedisPoolConfig;
*
* @author Dave Syer
* @author Andy Wilkinson
* @author Christian Dupuis
*/
@Configuration
@ConditionalOnClass({ JedisConnection.class, RedisOperations.class, Jedis.class })
@ -79,12 +80,13 @@ public class RedisAutoConfiguration {
@Bean
@ConditionalOnMissingBean
RedisConnectionFactory redisConnectionFactory() throws UnknownHostException {
if (this.properties.getPool() != null) {
JedisConnectionFactory factory = new JedisConnectionFactory(
jedisPoolConfig());
return factory;
JedisConnectionFactory factory = null;
if (this.properties.getPool() == null) {
factory = new JedisConnectionFactory();
}
else {
factory = new JedisConnectionFactory(jedisPoolConfig());
}
JedisConnectionFactory factory = new JedisConnectionFactory();
factory.setHostName(this.properties.getHost());
factory.setPort(this.properties.getPort());
if (this.properties.getPassword() != null) {

@ -29,6 +29,7 @@ import static org.junit.Assert.assertNotNull;
/**
* @author Dave Syer
* @author Christian Dupuis
*/
public class RedisAutoConfigurationTests {
@ -55,4 +56,18 @@ public class RedisAutoConfigurationTests {
.getHostName());
}
@Test
public void testRedisConfigurationWithPool() throws Exception {
this.context = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(this.context, "spring.redis.host:foo");
EnvironmentTestUtils.addEnvironment(this.context, "spring.redis.pool.max-idle:1");
this.context.register(RedisAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class);
this.context.refresh();
assertEquals("foo", this.context.getBean(JedisConnectionFactory.class)
.getHostName());
assertEquals(1, this.context.getBean(JedisConnectionFactory.class)
.getPoolConfig().getMaxIdle());
}
}

Loading…
Cancel
Save