Browse Source

Add database property to RedisProperties

Add database property to RedisProperties and use it in
RedisAutoConfiguration.

Fixes gh-1379
pull/1476/head
David Liu 12 years ago committed by Phillip Webb
parent
commit
b1ceb8a43b
  1. 2
      spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/redis/RedisAutoConfiguration.java
  2. 10
      spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/redis/RedisProperties.java
  3. 2
      spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/redis/RedisAutoConfigurationTests.java

2
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/redis/RedisAutoConfiguration.java

@ -65,6 +65,7 @@ public class RedisAutoConfiguration {
if (this.properties.getPassword() != null) { if (this.properties.getPassword() != null) {
factory.setPassword(this.properties.getPassword()); factory.setPassword(this.properties.getPassword());
} }
factory.setDatabase(this.properties.getDatabase());
return factory; return factory;
} }
@ -86,6 +87,7 @@ public class RedisAutoConfiguration {
if (this.properties.getPassword() != null) { if (this.properties.getPassword() != null) {
factory.setPassword(this.properties.getPassword()); factory.setPassword(this.properties.getPassword());
} }
factory.setDatabase(this.properties.getDatabase());
return factory; return factory;
} }

10
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/redis/RedisProperties.java

@ -26,6 +26,8 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
@ConfigurationProperties(prefix = "spring.redis") @ConfigurationProperties(prefix = "spring.redis")
public class RedisProperties { public class RedisProperties {
private int database = 0;
private String host = "localhost"; private String host = "localhost";
private String password; private String password;
@ -66,6 +68,14 @@ public class RedisProperties {
this.pool = pool; this.pool = pool;
} }
public int getDatabase() {
return this.database;
}
public void setDatabase(int database) {
this.database = database;
}
/** /**
* Pool properties. * Pool properties.
*/ */

2
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/redis/RedisAutoConfigurationTests.java

@ -51,11 +51,13 @@ public class RedisAutoConfigurationTests {
public void testOverrideRedisConfiguration() throws Exception { public void testOverrideRedisConfiguration() throws Exception {
this.context = new AnnotationConfigApplicationContext(); this.context = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(this.context, "spring.redis.host:foo"); EnvironmentTestUtils.addEnvironment(this.context, "spring.redis.host:foo");
EnvironmentTestUtils.addEnvironment(this.context, "spring.redis.database:1");
this.context.register(RedisAutoConfiguration.class, this.context.register(RedisAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class); PropertyPlaceholderAutoConfiguration.class);
this.context.refresh(); this.context.refresh();
assertEquals("foo", this.context.getBean(JedisConnectionFactory.class) assertEquals("foo", this.context.getBean(JedisConnectionFactory.class)
.getHostName()); .getHostName());
assertEquals(1, this.context.getBean(JedisConnectionFactory.class).getDatabase());
} }
@Test @Test

Loading…
Cancel
Save