Revisit InfluxDB configuration structure

This commit removes the `client` namespace for InfluxDB as the
component that is created is `InfluxDB`, not `InfluxDBClient` or
something.

This aligns with all the other url/user/password properties Spring
Boot provides already

See gh-9066
pull/6363/merge
Stephane Nicoll 8 years ago
parent 4a6b34e725
commit 540dca7bdd

@ -48,14 +48,13 @@ public class InfluxDbAutoConfiguration {
@Bean @Bean
@ConditionalOnMissingBean @ConditionalOnMissingBean
@ConditionalOnProperty("spring.influx.client.url") @ConditionalOnProperty("spring.influx.url")
public InfluxDB influxDb() { public InfluxDB influxDb() {
InfluxDbProperties.Client client = this.properties.getClient(); if (Strings.isNullOrEmpty(this.properties.getUser())) {
if (Strings.isNullOrEmpty(client.getUser())) { return InfluxDBFactory.connect(this.properties.getUrl());
return InfluxDBFactory.connect(client.getUrl());
} }
return InfluxDBFactory.connect(client.getUrl(), client.getUser(), return InfluxDBFactory.connect(this.properties.getUrl(), this.properties.getUser(),
client.getPassword()); this.properties.getPassword());
} }
} }

@ -28,53 +28,43 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
@ConfigurationProperties(prefix = "spring.influx") @ConfigurationProperties(prefix = "spring.influx")
public class InfluxDbProperties { public class InfluxDbProperties {
private final Client client = new Client(); /**
* Url of the InfluxDB instance to connect to.
public Client getClient() { */
return this.client; private String url;
/**
* Login user.
*/
private String user;
/**
* Login password.
*/
private String password;
public String getUrl() {
return this.url;
} }
public static class Client { public void setUrl(String url) {
this.url = url;
/** }
* Url of the InfluxDB instance to connect to.
*/
private String url;
/**
* Login user.
*/
private String user;
/**
* Login password.
*/
private String password;
public String getUrl() {
return this.url;
}
public void setUrl(String url) {
this.url = url;
}
public String getUser() {
return this.user;
}
public void setUser(String user) { public String getUser() {
this.user = user; return this.user;
} }
public String getPassword() { public void setUser(String user) {
return this.password; this.user = user;
} }
public void setPassword(String password) { public String getPassword() {
this.password = password; return this.password;
} }
public void setPassword(String password) {
this.password = password;
} }
} }

@ -43,22 +43,22 @@ public class InfluxDbAutoConfigurationTests {
} }
@Test @Test
public void clientRequiresUrl() { public void influxDbRequiresUrl() {
load(); load();
assertThat(this.context.getBeansOfType(InfluxDB.class)).isEmpty(); assertThat(this.context.getBeansOfType(InfluxDB.class)).isEmpty();
} }
@Test @Test
public void clientCanBeCustomized() { public void influxDbCanBeCustomized() {
load("spring.influx.client.url=http://localhost", load("spring.influx.url=http://localhost",
"spring.influx.client.password:password", "spring.influx.password:password",
"spring.influx.client.user:user"); "spring.influx.user:user");
assertThat(this.context.getBeansOfType(InfluxDB.class)).hasSize(1); assertThat(this.context.getBeansOfType(InfluxDB.class)).hasSize(1);
} }
@Test @Test
public void clientCanBeCreatedWithoutCredentials() { public void influxDbCanBeCreatedWithoutCredentials() {
load("spring.influx.client.url=http://localhost"); load("spring.influx.url=http://localhost");
assertThat(this.context.getBeansOfType(InfluxDB.class)).hasSize(1); assertThat(this.context.getBeansOfType(InfluxDB.class)).hasSize(1);
} }

@ -715,9 +715,9 @@ content into your application; rather pick only the properties that you need.
spring.h2.console.settings.web-allow-others=false # Enable remote access. spring.h2.console.settings.web-allow-others=false # Enable remote access.
# InfluxDB ({sc-spring-boot-autoconfigure}/influx/InfluxProperties.{sc-ext}[InfluxProperties]) # InfluxDB ({sc-spring-boot-autoconfigure}/influx/InfluxProperties.{sc-ext}[InfluxProperties])
spring.influx.client.password= # Login password. spring.influx.password= # Login password.
spring.influx.client.url= # Url of the InfluxDB instance to connect to. spring.influx.url= # Url of the InfluxDB instance to connect to.
spring.influx.client.user= # Login user. spring.influx.user= # Login user.
# JOOQ ({sc-spring-boot-autoconfigure}/jooq/JooqAutoConfiguration.{sc-ext}[JooqAutoConfiguration]) # JOOQ ({sc-spring-boot-autoconfigure}/jooq/JooqAutoConfiguration.{sc-ext}[JooqAutoConfiguration])
spring.jooq.sql-dialect= # Sql dialect to use, auto-detected by default. spring.jooq.sql-dialect= # Sql dialect to use, auto-detected by default.

Loading…
Cancel
Save