Add database property to RedisProperties
Add database property to RedisProperties and use it in RedisAutoConfiguration. Fixes gh-1379
This commit is contained in:
parent
2186da453f
commit
b1ceb8a43b
|
@ -65,6 +65,7 @@ public class RedisAutoConfiguration {
|
|||
if (this.properties.getPassword() != null) {
|
||||
factory.setPassword(this.properties.getPassword());
|
||||
}
|
||||
factory.setDatabase(this.properties.getDatabase());
|
||||
return factory;
|
||||
}
|
||||
|
||||
|
@ -86,6 +87,7 @@ public class RedisAutoConfiguration {
|
|||
if (this.properties.getPassword() != null) {
|
||||
factory.setPassword(this.properties.getPassword());
|
||||
}
|
||||
factory.setDatabase(this.properties.getDatabase());
|
||||
return factory;
|
||||
}
|
||||
|
||||
|
|
|
@ -26,6 +26,8 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
|
|||
@ConfigurationProperties(prefix = "spring.redis")
|
||||
public class RedisProperties {
|
||||
|
||||
private int database = 0;
|
||||
|
||||
private String host = "localhost";
|
||||
|
||||
private String password;
|
||||
|
@ -66,6 +68,14 @@ public class RedisProperties {
|
|||
this.pool = pool;
|
||||
}
|
||||
|
||||
public int getDatabase() {
|
||||
return this.database;
|
||||
}
|
||||
|
||||
public void setDatabase(int database) {
|
||||
this.database = database;
|
||||
}
|
||||
|
||||
/**
|
||||
* Pool properties.
|
||||
*/
|
||||
|
|
|
@ -51,11 +51,13 @@ public class RedisAutoConfigurationTests {
|
|||
public void testOverrideRedisConfiguration() throws Exception {
|
||||
this.context = new AnnotationConfigApplicationContext();
|
||||
EnvironmentTestUtils.addEnvironment(this.context, "spring.redis.host:foo");
|
||||
EnvironmentTestUtils.addEnvironment(this.context, "spring.redis.database: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).getDatabase());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Reference in New Issue