diff --git a/spring-boot-project/spring-boot-autoconfigure/build.gradle b/spring-boot-project/spring-boot-autoconfigure/build.gradle index 8edc919f17..a4717f29c5 100644 --- a/spring-boot-project/spring-boot-autoconfigure/build.gradle +++ b/spring-boot-project/spring-boot-autoconfigure/build.gradle @@ -23,7 +23,6 @@ dependencies { optional("com.hazelcast:hazelcast") optional("com.hazelcast:hazelcast-spring") optional("com.h2database:h2") - optional("com.influxdb:influxdb-client-java") optional("com.nimbusds:oauth2-oidc-sdk") optional("com.oracle.database.jdbc:ojdbc8") optional("com.oracle.database.jdbc:ucp") diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/influx/InfluxDbAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/influx/InfluxDbAutoConfiguration.java index 2b1cc5d6c5..e1cf2ec787 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/influx/InfluxDbAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/influx/InfluxDbAutoConfiguration.java @@ -16,10 +16,6 @@ package org.springframework.boot.autoconfigure.influx; -import com.influxdb.client.InfluxDBClient; -import com.influxdb.client.InfluxDBClientFactory; -import com.influxdb.client.InfluxDBClientOptions; -import com.influxdb.client.InfluxDBClientOptions.Builder; import okhttp3.OkHttpClient; import org.influxdb.InfluxDB; import org.influxdb.impl.InfluxDBImpl; @@ -32,7 +28,6 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.util.StringUtils; /** * {@link EnableAutoConfiguration Auto-configuration} for InfluxDB. @@ -43,10 +38,21 @@ import org.springframework.util.StringUtils; * @since 2.0.0 */ @Configuration(proxyBeanMethods = false) -@ConditionalOnProperty("spring.influx.url") +@ConditionalOnClass(InfluxDB.class) @EnableConfigurationProperties(InfluxDbProperties.class) public class InfluxDbAutoConfiguration { + @Bean + @ConditionalOnMissingBean + @ConditionalOnProperty("spring.influx.url") + public InfluxDB influxDb(InfluxDbProperties properties, ObjectProvider builder, + ObjectProvider customizers) { + InfluxDB influxDb = new InfluxDBImpl(properties.getUrl(), properties.getUser(), properties.getPassword(), + determineBuilder(builder.getIfAvailable())); + customizers.orderedStream().forEach((customizer) -> customizer.customize(influxDb)); + return influxDb; + } + private static OkHttpClient.Builder determineBuilder(InfluxDbOkHttpClientBuilderProvider builder) { if (builder != null) { return builder.get(); @@ -54,40 +60,4 @@ public class InfluxDbAutoConfiguration { return new OkHttpClient.Builder(); } - @Configuration(proxyBeanMethods = false) - @ConditionalOnClass(InfluxDB.class) - static class Influx1xConfiguration { - - @Bean - @ConditionalOnMissingBean - InfluxDB influxDb(InfluxDbProperties properties, ObjectProvider builder, - ObjectProvider customizers) { - InfluxDB influxDb = new InfluxDBImpl(properties.getUrl(), properties.getUser(), properties.getPassword(), - determineBuilder(builder.getIfAvailable())); - customizers.orderedStream().forEach((customizer) -> customizer.customize(influxDb)); - return influxDb; - } - - } - - @Configuration(proxyBeanMethods = false) - @ConditionalOnClass(InfluxDBClient.class) - static class Influx2xConfiguration { - - @Bean - @ConditionalOnMissingBean - InfluxDBClient influxDbClient(InfluxDbProperties properties, - ObjectProvider httpClientBuilder, - ObjectProvider customizers) { - Builder builder = InfluxDBClientOptions.builder().url(properties.getUrl()); - if (StringUtils.hasText(properties.getUser()) && StringUtils.hasText(properties.getPassword())) { - builder.authenticate(properties.getUser(), properties.getPassword().toCharArray()); - } - builder.okHttpClient(determineBuilder(httpClientBuilder.getIfAvailable())); - customizers.orderedStream().forEach((customizer) -> customizer.customize(builder)); - return InfluxDBClientFactory.create(builder.build()); - } - - } - } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/influx/InfluxDbClientOptionsBuilderCustomizer.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/influx/InfluxDbClientOptionsBuilderCustomizer.java deleted file mode 100644 index d1cfb78c2f..0000000000 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/influx/InfluxDbClientOptionsBuilderCustomizer.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2012-2021 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.boot.autoconfigure.influx; - -import com.influxdb.client.InfluxDBClient; -import com.influxdb.client.InfluxDBClientOptions; - -/** - * Callback interface that can be implemented by beans wishing to further customize - * {@link InfluxDBClientOptions} used to configure an {@link InfluxDBClient} whilst - * retaining default auto-configuration. - * - * @author Stephane Nicoll - * @since 2.6.0 - */ -@FunctionalInterface -public interface InfluxDbClientOptionsBuilderCustomizer { - - /** - * Customize the {@link InfluxDBClientOptions}. - * @param builder the influxDB client options builder to customize - */ - void customize(InfluxDBClientOptions.Builder builder); - -} diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/influx/InfluxDbAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/influx/InfluxDbAutoConfigurationTests.java index 00c1377d3a..34033cd669 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/influx/InfluxDbAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/influx/InfluxDbAutoConfigurationTests.java @@ -17,12 +17,8 @@ package org.springframework.boot.autoconfigure.influx; import java.util.concurrent.TimeUnit; -import java.util.function.Consumer; -import com.influxdb.client.InfluxDBClient; -import com.influxdb.client.InfluxDBClientOptions; import okhttp3.OkHttpClient; -import org.assertj.core.api.InstanceOfAssertFactories; import org.influxdb.InfluxDB; import org.junit.jupiter.api.Test; import retrofit2.Retrofit; @@ -30,7 +26,6 @@ import retrofit2.Retrofit; import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.test.context.assertj.AssertableApplicationContext; import org.springframework.boot.test.context.runner.ApplicationContextRunner; -import org.springframework.boot.test.context.runner.ContextConsumer; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.test.util.ReflectionTestUtils; @@ -91,42 +86,6 @@ class InfluxDbAutoConfigurationTests { }); } - @Test - void influxDbClientRequiresUrl() { - this.contextRunner.run((context) -> assertThat(context).doesNotHaveBean(InfluxDBClient.class)); - } - - @Test - void influxDbClientCanBeCustomized() { - this.contextRunner - .withPropertyValues("spring.influx.url=http://localhost", "spring.influx.user=user", - "spring.influx.password=password") - .run((context) -> assertThat(context).hasSingleBean(InfluxDBClient.class)); - } - - @Test - void influxDbClientCanBeCreatedWithoutCredentials() { - this.contextRunner.withPropertyValues("spring.influx.url=http://localhost").run(assertInfluxDbClientOptions( - (options) -> assertThat(options.getOkHttpClient().build().readTimeoutMillis()).isEqualTo(10000))); - } - - @Test - void influxDbClientWithOkHttpClientBuilderProvider() { - this.contextRunner.withUserConfiguration(CustomOkHttpClientBuilderProviderConfig.class) - .withPropertyValues("spring.influx.url=http://localhost") - .run(assertInfluxDbClientOptions( - (options) -> assertThat(options.getOkHttpClient().build().readTimeoutMillis()) - .isEqualTo(40000))); - } - - @Test - void influxDbClientWithCustomizer() { - this.contextRunner - .withBean(InfluxDbClientOptionsBuilderCustomizer.class, () -> (options) -> options.org("my_org")) - .withPropertyValues("spring.influx.url=http://localhost") - .run(assertInfluxDbClientOptions((options) -> assertThat(options.getOrg()).isEqualTo("my_org"))); - } - private int getReadTimeoutProperty(AssertableApplicationContext context) { InfluxDB influxDb = context.getBean(InfluxDB.class); Retrofit retrofit = (Retrofit) ReflectionTestUtils.getField(influxDb, "retrofit"); @@ -134,16 +93,6 @@ class InfluxDbAutoConfigurationTests { return callFactory.readTimeoutMillis(); } - private ContextConsumer assertInfluxDbClientOptions( - Consumer options) { - return (context) -> { - assertThat(context).hasSingleBean(InfluxDBClient.class); - assertThat(context).getBean(InfluxDBClient.class) - .extracting("options", InstanceOfAssertFactories.type(InfluxDBClientOptions.class)) - .satisfies(options); - }; - } - @Configuration(proxyBeanMethods = false) static class CustomOkHttpClientBuilderProviderConfig { diff --git a/spring-boot-project/spring-boot-dependencies/build.gradle b/spring-boot-project/spring-boot-dependencies/build.gradle index a73817c6a4..f8d696e677 100644 --- a/spring-boot-project/spring-boot-dependencies/build.gradle +++ b/spring-boot-project/spring-boot-dependencies/build.gradle @@ -526,13 +526,6 @@ bom { ] } } - library("InfluxDB Client Java", "2.3.0") { - group("com.influxdb") { - modules = [ - "influxdb-client-java" - ] - } - } library("InfluxDB Java", "2.21") { group("org.influxdb") { modules = [ diff --git a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/data/nosql.adoc b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/data/nosql.adoc index 4adf9c0b62..3719c3de8f 100644 --- a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/data/nosql.adoc +++ b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/data/nosql.adoc @@ -634,7 +634,7 @@ https://www.influxdata.com/[InfluxDB] is an open-source time series database opt [[data.nosql.influxdb.connecting]] ==== Connecting to InfluxDB -Spring Boot auto-configures a client instance, provided that either `influxdb-java` (Influx 1.x) or `influxdb-client-java` (Influx 2.x) is on the classpath and the URL of the database is set, as shown in the following example: +Spring Boot auto-configures an `InfluxDB` instance, provided the `influxdb-java` client is on the classpath and the URL of the database is set, as shown in the following example: [source,yaml,indent=0,subs="verbatim",configprops,configblocks] ---- @@ -648,4 +648,4 @@ If the connection to InfluxDB requires a user and password, you can set the `spr InfluxDB relies on OkHttp. If you need to tune the http client `InfluxDB` uses behind the scenes, you can register an `InfluxDbOkHttpClientBuilderProvider` bean. -If you need more control over the configuration, consider registering an `InfluxDbCustomizer` (Influx 1.x), or an `InfluxDbClientOptionsBuilderCustomizer` (Influx 2.x) bean. +If you need more control over the configuration, consider registering an `InfluxDbCustomizer` bean.