Remove support for Elasticsearch transport client

The Elasticsearch transport client has been deprecated since Spring Boot
2.2.0 and is about to be removed from Spring Data Elasticsearch and
Elasticsearch itself in their next major releases.

The available REST client support variants are now the preferred way of
using Elasticsearch features.

Closes gh-19668
pull/19681/head
Brian Clozel 5 years ago
parent 648e468c86
commit b780e5247c

@ -128,7 +128,9 @@ dependencies {
testImplementation 'org.mockito:mockito-core'
testImplementation 'org.skyscreamer:jsonassert'
testImplementation 'org.springframework:spring-orm'
testImplementation 'org.springframework.data:spring-data-elasticsearch'
testImplementation ('org.springframework.data:spring-data-elasticsearch') {
exclude group: 'org.elasticsearch.client', module: 'transport'
}
testImplementation 'org.springframework.data:spring-data-rest-webmvc'
testImplementation 'org.springframework.integration:spring-integration-jmx'
testImplementation 'org.springframework.restdocs:spring-restdocs-mockmvc'

@ -1,76 +0,0 @@
/*
* Copyright 2012-2019 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.actuate.autoconfigure.elasticsearch;
import java.time.Duration;
import java.util.Map;
import org.elasticsearch.client.Client;
import org.springframework.boot.actuate.autoconfigure.health.CompositeHealthContributorConfiguration;
import org.springframework.boot.actuate.autoconfigure.health.ConditionalOnEnabledHealthIndicator;
import org.springframework.boot.actuate.elasticsearch.ElasticsearchHealthIndicator;
import org.springframework.boot.actuate.health.HealthContributor;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.data.elasticsearch.ElasticsearchAutoConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* {@link EnableAutoConfiguration Auto-configuration} for
* {@link ElasticsearchHealthIndicator} using the Elasticsearch {@link Client}.
*
* @author Stephane Nicoll
* @since 2.1.0
* @deprecated since 2.2.0 as {@literal org.elasticsearch.client:transport} has been
* deprecated upstream
*/
@Configuration(proxyBeanMethods = false)
@ConditionalOnClass(Client.class)
@ConditionalOnBean(Client.class)
@ConditionalOnEnabledHealthIndicator("elasticsearch")
@AutoConfigureAfter(ElasticsearchAutoConfiguration.class)
@EnableConfigurationProperties(ElasticsearchHealthIndicatorProperties.class)
@Deprecated
public class ElasticSearchClientHealthContributorAutoConfiguration
extends CompositeHealthContributorConfiguration<ElasticsearchHealthIndicator, Client> {
private final ElasticsearchHealthIndicatorProperties properties;
public ElasticSearchClientHealthContributorAutoConfiguration(ElasticsearchHealthIndicatorProperties properties) {
this.properties = properties;
}
@Bean
@ConditionalOnMissingBean(name = { "elasticsearchHealthIndicator", "elasticsearchHealthContributor" })
public HealthContributor elasticsearchHealthContributor(Map<String, Client> clients) {
return createContributor(clients);
}
@Override
protected ElasticsearchHealthIndicator createIndicator(Client client) {
Duration responseTimeout = this.properties.getResponseTimeout();
return new ElasticsearchHealthIndicator(client, (responseTimeout != null) ? responseTimeout.toMillis() : 100,
this.properties.getIndices());
}
}

@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2020 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.
@ -45,7 +45,7 @@ import org.springframework.context.annotation.Configuration;
@ConditionalOnClass(JestClient.class)
@ConditionalOnBean(JestClient.class)
@ConditionalOnEnabledHealthIndicator("elasticsearch")
@AutoConfigureAfter({ JestAutoConfiguration.class, ElasticSearchClientHealthContributorAutoConfiguration.class })
@AutoConfigureAfter(JestAutoConfiguration.class)
@Deprecated
public class ElasticSearchJestHealthContributorAutoConfiguration
extends CompositeHealthContributorConfiguration<ElasticsearchJestHealthIndicator, JestClient> {

@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2020 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.
@ -44,7 +44,7 @@ import org.springframework.context.annotation.Configuration;
@ConditionalOnClass(RestClient.class)
@ConditionalOnBean(RestClient.class)
@ConditionalOnEnabledHealthIndicator("elasticsearch")
@AutoConfigureAfter({ RestClientAutoConfiguration.class, ElasticSearchClientHealthContributorAutoConfiguration.class })
@AutoConfigureAfter(RestClientAutoConfiguration.class)
@SuppressWarnings("deprecation")
public class ElasticSearchRestHealthContributorAutoConfiguration
extends CompositeHealthContributorConfiguration<ElasticsearchRestHealthIndicator, RestClient> {

@ -1,68 +0,0 @@
/*
* Copyright 2012-2019 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.actuate.autoconfigure.elasticsearch;
import java.time.Duration;
import java.util.ArrayList;
import java.util.List;
import org.springframework.boot.actuate.elasticsearch.ElasticsearchHealthIndicator;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.DeprecatedConfigurationProperty;
/**
* External configuration properties for {@link ElasticsearchHealthIndicator}.
*
* @author Binwei Yang
* @author Andy Wilkinson
* @since 2.0.0
* @deprecated since 2.2.0 as {@literal org.elasticsearch.client:transport} has been
* deprecated upstream
*/
@ConfigurationProperties(prefix = "management.health.elasticsearch", ignoreUnknownFields = false)
@Deprecated
public class ElasticsearchHealthIndicatorProperties {
/**
* Comma-separated index names.
*/
private List<String> indices = new ArrayList<>();
/**
* Time to wait for a response from the cluster.
*/
private Duration responseTimeout = Duration.ofMillis(100);
@DeprecatedConfigurationProperty(reason = "Upstream elasticsearch transport is deprected")
public List<String> getIndices() {
return this.indices;
}
public void setIndices(List<String> indices) {
this.indices = indices;
}
@DeprecatedConfigurationProperty(reason = "Upstream elasticsearch transport is deprected")
public Duration getResponseTimeout() {
return this.responseTimeout;
}
public void setResponseTimeout(Duration responseTimeout) {
this.responseTimeout = responseTimeout;
}
}

@ -13,7 +13,6 @@ org.springframework.boot.actuate.autoconfigure.context.properties.ConfigurationP
org.springframework.boot.actuate.autoconfigure.context.ShutdownEndpointAutoConfiguration,\
org.springframework.boot.actuate.autoconfigure.couchbase.CouchbaseHealthContributorAutoConfiguration,\
org.springframework.boot.actuate.autoconfigure.couchbase.CouchbaseReactiveHealthContributorAutoConfiguration,\
org.springframework.boot.actuate.autoconfigure.elasticsearch.ElasticSearchClientHealthContributorAutoConfiguration,\
org.springframework.boot.actuate.autoconfigure.elasticsearch.ElasticSearchJestHealthContributorAutoConfiguration,\
org.springframework.boot.actuate.autoconfigure.elasticsearch.ElasticSearchRestHealthContributorAutoConfiguration,\
org.springframework.boot.actuate.autoconfigure.endpoint.EndpointAutoConfiguration,\

@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2020 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.
@ -66,29 +66,23 @@ class SpringApplicationHierarchyTests {
}
@Configuration
@EnableAutoConfiguration(
exclude = { ElasticsearchDataAutoConfiguration.class, ElasticsearchRepositoriesAutoConfiguration.class,
CassandraAutoConfiguration.class, CassandraDataAutoConfiguration.class,
MongoDataAutoConfiguration.class, MongoReactiveDataAutoConfiguration.class,
Neo4jDataAutoConfiguration.class, Neo4jRepositoriesAutoConfiguration.class,
RedisAutoConfiguration.class, RedisRepositoriesAutoConfiguration.class,
FlywayAutoConfiguration.class, MetricsAutoConfiguration.class },
excludeName = {
"org.springframework.boot.autoconfigure.data.elasticsearch.ElasticsearchAutoConfiguration" })
@EnableAutoConfiguration(exclude = { ElasticsearchDataAutoConfiguration.class,
ElasticsearchRepositoriesAutoConfiguration.class, CassandraAutoConfiguration.class,
CassandraDataAutoConfiguration.class, MongoDataAutoConfiguration.class,
MongoReactiveDataAutoConfiguration.class, Neo4jDataAutoConfiguration.class,
Neo4jRepositoriesAutoConfiguration.class, RedisAutoConfiguration.class,
RedisRepositoriesAutoConfiguration.class, FlywayAutoConfiguration.class, MetricsAutoConfiguration.class })
static class Parent {
}
@Configuration
@EnableAutoConfiguration(
exclude = { ElasticsearchDataAutoConfiguration.class, ElasticsearchRepositoriesAutoConfiguration.class,
CassandraAutoConfiguration.class, CassandraDataAutoConfiguration.class,
MongoDataAutoConfiguration.class, MongoReactiveDataAutoConfiguration.class,
Neo4jDataAutoConfiguration.class, Neo4jRepositoriesAutoConfiguration.class,
RedisAutoConfiguration.class, RedisRepositoriesAutoConfiguration.class,
FlywayAutoConfiguration.class, MetricsAutoConfiguration.class },
excludeName = {
"org.springframework.boot.autoconfigure.data.elasticsearch.ElasticsearchAutoConfiguration" })
@EnableAutoConfiguration(exclude = { ElasticsearchDataAutoConfiguration.class,
ElasticsearchRepositoriesAutoConfiguration.class, CassandraAutoConfiguration.class,
CassandraDataAutoConfiguration.class, MongoDataAutoConfiguration.class,
MongoReactiveDataAutoConfiguration.class, Neo4jDataAutoConfiguration.class,
Neo4jRepositoriesAutoConfiguration.class, RedisAutoConfiguration.class,
RedisRepositoriesAutoConfiguration.class, FlywayAutoConfiguration.class, MetricsAutoConfiguration.class })
static class Child {
}

@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2020 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.
@ -23,15 +23,13 @@ import org.springframework.boot.actuate.autoconfigure.health.HealthContributorAu
import org.springframework.boot.actuate.elasticsearch.ElasticsearchHealthIndicator;
import org.springframework.boot.actuate.elasticsearch.ElasticsearchJestHealthIndicator;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.autoconfigure.data.elasticsearch.ElasticsearchAutoConfiguration;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
/**
* Tests for {@link ElasticSearchClientHealthContributorAutoConfiguration} and
* {@link ElasticSearchJestHealthContributorAutoConfiguration}.
* Tests for {@link ElasticSearchJestHealthContributorAutoConfiguration}.
*
* @author Phillip Webb
*/
@ -39,17 +37,7 @@ import static org.mockito.Mockito.mock;
class ElasticsearchHealthContributorAutoConfigurationTests {
private ApplicationContextRunner contextRunner = new ApplicationContextRunner().withConfiguration(AutoConfigurations
.of(ElasticsearchAutoConfiguration.class, ElasticSearchClientHealthContributorAutoConfiguration.class,
ElasticSearchJestHealthContributorAutoConfiguration.class,
HealthContributorAutoConfiguration.class));
@Test
void runShouldCreateIndicator() {
this.contextRunner.withPropertyValues("spring.data.elasticsearch.cluster-nodes:localhost:0")
.withSystemProperties("es.set.netty.runtime.available.processors=false")
.run((context) -> assertThat(context).hasSingleBean(ElasticsearchHealthIndicator.class)
.doesNotHaveBean(ElasticsearchJestHealthIndicator.class));
}
.of(ElasticSearchJestHealthContributorAutoConfiguration.class, HealthContributorAutoConfiguration.class));
@Test
void runWhenUsingJestClientShouldCreateIndicator() {

@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2020 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.
@ -80,7 +80,6 @@ class WebEndpointsAutoConfigurationIntegrationTests {
Neo4jRepositoriesAutoConfiguration.class, MongoAutoConfiguration.class, MongoDataAutoConfiguration.class,
MongoReactiveAutoConfiguration.class, MongoReactiveDataAutoConfiguration.class,
RepositoryRestMvcAutoConfiguration.class, HazelcastAutoConfiguration.class,
org.springframework.boot.autoconfigure.data.elasticsearch.ElasticsearchAutoConfiguration.class,
ElasticsearchDataAutoConfiguration.class,
org.springframework.boot.autoconfigure.elasticsearch.jest.JestAutoConfiguration.class,
SolrRepositoriesAutoConfiguration.class, SolrAutoConfiguration.class, RedisAutoConfiguration.class,

@ -115,7 +115,9 @@ dependencies {
optional 'org.springframework.data:spring-data-jpa'
optional 'org.springframework.data:spring-data-rest-webmvc'
optional 'org.springframework.data:spring-data-cassandra'
optional 'org.springframework.data:spring-data-elasticsearch'
optional ('org.springframework.data:spring-data-elasticsearch') {
exclude group: 'org.elasticsearch.client', module: 'transport'
}
optional 'org.springframework.data:spring-data-jdbc'
optional 'org.springframework.data:spring-data-ldap'
optional 'org.springframework.data:spring-data-mongodb'

@ -1,70 +0,0 @@
/*
* Copyright 2012-2019 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.data.elasticsearch;
import java.util.Properties;
import org.elasticsearch.client.Client;
import org.elasticsearch.client.transport.TransportClient;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
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.data.elasticsearch.client.TransportClientFactoryBean;
/**
* {@link org.springframework.boot.autoconfigure.EnableAutoConfiguration
* Auto-configuration} for Elasticsearch.
*
* @author Artur Konczak
* @author Mohsin Husen
* @author Andy Wilkinson
* @since 1.1.0
*/
@Configuration(proxyBeanMethods = false)
@ConditionalOnClass({ Client.class, TransportClientFactoryBean.class })
@ConditionalOnProperty(prefix = "spring.data.elasticsearch", name = "cluster-nodes", matchIfMissing = false)
@EnableConfigurationProperties(ElasticsearchProperties.class)
public class ElasticsearchAutoConfiguration {
private final ElasticsearchProperties properties;
public ElasticsearchAutoConfiguration(ElasticsearchProperties properties) {
this.properties = properties;
}
@Bean
@ConditionalOnMissingBean
public TransportClient elasticsearchClient() throws Exception {
TransportClientFactoryBean factory = new TransportClientFactoryBean();
factory.setClusterNodes(this.properties.getClusterNodes());
factory.setProperties(createProperties());
factory.afterPropertiesSet();
return factory.getObject();
}
private Properties createProperties() {
Properties properties = new Properties();
properties.put("cluster.name", this.properties.getClusterName());
properties.putAll(this.properties.getProperties());
return properties;
}
}

@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2020 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.
@ -29,9 +29,6 @@ import org.springframework.data.elasticsearch.repository.config.EnableReactiveEl
/**
* {@link EnableAutoConfiguration Auto-configuration} for Spring Data's Elasticsearch
* support.
* <p>
* Registers an {@link ElasticsearchTemplate} if no other bean of the same type and the
* same name {@code "elasticsearchTemplate"} is configured.
*
* @author Brian Clozel
* @author Artur Konczak
@ -42,10 +39,8 @@ import org.springframework.data.elasticsearch.repository.config.EnableReactiveEl
*/
@Configuration(proxyBeanMethods = false)
@ConditionalOnClass({ ElasticsearchTemplate.class })
@AutoConfigureAfter({ ElasticsearchAutoConfiguration.class, RestClientAutoConfiguration.class,
ReactiveRestClientAutoConfiguration.class })
@AutoConfigureAfter({ RestClientAutoConfiguration.class, ReactiveRestClientAutoConfiguration.class })
@Import({ ElasticsearchDataConfiguration.BaseConfiguration.class,
ElasticsearchDataConfiguration.TransportClientConfiguration.class,
ElasticsearchDataConfiguration.RestClientConfiguration.class,
ElasticsearchDataConfiguration.ReactiveRestClientConfiguration.class })
public class ElasticsearchDataAutoConfiguration {

@ -18,7 +18,6 @@ package org.springframework.boot.autoconfigure.data.elasticsearch;
import org.elasticsearch.action.support.IndicesOptions;
import org.elasticsearch.action.support.WriteRequest;
import org.elasticsearch.client.Client;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
@ -29,7 +28,6 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.data.elasticsearch.client.reactive.ReactiveElasticsearchClient;
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
import org.springframework.data.elasticsearch.core.ReactiveElasticsearchOperations;
import org.springframework.data.elasticsearch.core.ReactiveElasticsearchTemplate;
import org.springframework.data.elasticsearch.core.convert.ElasticsearchConverter;
@ -78,25 +76,6 @@ abstract class ElasticsearchDataConfiguration {
}
@Configuration(proxyBeanMethods = false)
@ConditionalOnClass(Client.class)
static class TransportClientConfiguration {
@Bean
@ConditionalOnMissingBean(value = ElasticsearchOperations.class, name = "elasticsearchTemplate")
@ConditionalOnBean(Client.class)
@Deprecated
ElasticsearchTemplate elasticsearchTemplate(Client client, ElasticsearchConverter converter) {
try {
return new ElasticsearchTemplate(client, converter);
}
catch (Exception ex) {
throw new IllegalStateException(ex);
}
}
}
@Configuration(proxyBeanMethods = false)
@ConditionalOnClass({ WebClient.class, ReactiveElasticsearchOperations.class })
static class ReactiveRestClientConfiguration {

@ -1,73 +0,0 @@
/*
* Copyright 2012-2019 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.data.elasticsearch;
import java.util.HashMap;
import java.util.Map;
import org.springframework.boot.context.properties.ConfigurationProperties;
/**
* Configuration properties for Elasticsearch.
*
* @author Artur Konczak
* @author Mohsin Husen
* @since 1.1.0
*/
@ConfigurationProperties(prefix = "spring.data.elasticsearch")
public class ElasticsearchProperties {
/**
* Elasticsearch cluster name.
*/
private String clusterName = "elasticsearch";
/**
* Comma-separated list of cluster node addresses.
*/
private String clusterNodes;
/**
* Additional properties used to configure the client.
*/
private Map<String, String> properties = new HashMap<>();
public String getClusterName() {
return this.clusterName;
}
public void setClusterName(String clusterName) {
this.clusterName = clusterName;
}
public String getClusterNodes() {
return this.clusterNodes;
}
public void setClusterNodes(String clusterNodes) {
this.clusterNodes = clusterNodes;
}
public Map<String, String> getProperties() {
return this.properties;
}
public void setProperties(Map<String, String> properties) {
this.properties = properties;
}
}

@ -348,30 +348,6 @@
"level": "error"
}
},
{
"name": "spring.data.elasticsearch.cluster-name",
"type": "java.lang.String",
"description": "Elasticsearch cluster name.",
"deprecation": {
"reason": "The transport client support is deprecated. Use other supported clients instead."
}
},
{
"name": "spring.data.elasticsearch.cluster-nodes",
"type": "java.lang.String",
"description": "Comma-separated list of cluster node addresses.",
"deprecation": {
"reason": "The transport client support is deprecated. Use other supported clients instead."
}
},
{
"name": "spring.data.elasticsearch.properties",
"type": "java.util.Map<java.lang.String,java.lang.String>",
"description": "Additional properties used to configure the client.",
"deprecation": {
"reason": "The transport client support is deprecated. Use other supported clients instead."
}
},
{
"name": "spring.data.elasticsearch.repositories.enabled",
"type": "java.lang.Boolean",

@ -39,7 +39,6 @@ org.springframework.boot.autoconfigure.data.couchbase.CouchbaseDataAutoConfigura
org.springframework.boot.autoconfigure.data.couchbase.CouchbaseReactiveDataAutoConfiguration,\
org.springframework.boot.autoconfigure.data.couchbase.CouchbaseReactiveRepositoriesAutoConfiguration,\
org.springframework.boot.autoconfigure.data.couchbase.CouchbaseRepositoriesAutoConfiguration,\
org.springframework.boot.autoconfigure.data.elasticsearch.ElasticsearchAutoConfiguration,\
org.springframework.boot.autoconfigure.data.elasticsearch.ElasticsearchDataAutoConfiguration,\
org.springframework.boot.autoconfigure.data.elasticsearch.ElasticsearchRepositoriesAutoConfiguration,\
org.springframework.boot.autoconfigure.data.elasticsearch.ReactiveElasticsearchRepositoriesAutoConfiguration,\

@ -1,102 +0,0 @@
/*
* Copyright 2012-2020 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.data.elasticsearch;
import java.time.Duration;
import java.util.List;
import org.elasticsearch.client.Client;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.cluster.node.DiscoveryNode;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.testcontainers.elasticsearch.ElasticsearchContainer;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
/**
* Tests for {@link ElasticsearchAutoConfiguration}.
*
* @author Phillip Webb
* @author Andy Wilkinson
*/
@Testcontainers(disabledWithoutDocker = true)
class ElasticsearchAutoConfigurationTests {
@Container
public static ElasticsearchContainer elasticsearch = new VersionOverridingElasticsearchContainer()
.withStartupAttempts(5).withStartupTimeout(Duration.ofMinutes(10));
private AnnotationConfigApplicationContext context;
@BeforeEach
void setUp() {
System.setProperty("es.set.netty.runtime.available.processors", "false");
}
@AfterEach
void close() {
if (this.context != null) {
this.context.close();
}
System.clearProperty("es.set.netty.runtime.available.processors");
}
@Test
void useExistingClient() {
this.context = new AnnotationConfigApplicationContext();
this.context.register(CustomConfiguration.class, PropertyPlaceholderAutoConfiguration.class,
ElasticsearchAutoConfiguration.class);
this.context.refresh();
assertThat(this.context.getBeanNamesForType(Client.class)).hasSize(1);
assertThat(this.context.getBean("myClient")).isSameAs(this.context.getBean(Client.class));
}
@Test
@SuppressWarnings("deprecation")
void createTransportClient() {
this.context = new AnnotationConfigApplicationContext();
TestPropertyValues
.of("spring.data.elasticsearch.cluster-nodes:" + elasticsearch.getTcpHost().getHostString() + ":"
+ elasticsearch.getTcpHost().getPort(), "spring.data.elasticsearch.cluster-name:docker-cluster")
.applyTo(this.context);
this.context.register(PropertyPlaceholderAutoConfiguration.class, ElasticsearchAutoConfiguration.class);
this.context.refresh();
List<DiscoveryNode> connectedNodes = this.context.getBean(TransportClient.class).connectedNodes();
assertThat(connectedNodes).hasSize(1);
}
@Configuration(proxyBeanMethods = false)
static class CustomConfiguration {
@Bean
Client myClient() {
return mock(Client.class);
}
}
}

@ -16,14 +16,9 @@
package org.springframework.boot.autoconfigure.data.elasticsearch;
import java.time.Duration;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.testcontainers.elasticsearch.ElasticsearchContainer;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.autoconfigure.elasticsearch.rest.RestClientAutoConfiguration;
@ -31,10 +26,8 @@ import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
import org.springframework.data.elasticsearch.core.ReactiveElasticsearchTemplate;
import org.springframework.data.elasticsearch.core.convert.ElasticsearchConverter;
import org.springframework.data.elasticsearch.core.mapping.SimpleElasticsearchMappingContext;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
@ -48,15 +41,10 @@ import static org.mockito.Mockito.mock;
* @author Peter-Josef Meisch
* @author Scott Frederick
*/
@Testcontainers(disabledWithoutDocker = true)
class ElasticsearchDataAutoConfigurationTests {
@Container
static ElasticsearchContainer elasticsearch = new VersionOverridingElasticsearchContainer().withStartupAttempts(5)
.withStartupTimeout(Duration.ofMinutes(10));
private ApplicationContextRunner contextRunner = new ApplicationContextRunner().withConfiguration(
AutoConfigurations.of(ElasticsearchAutoConfiguration.class, RestClientAutoConfiguration.class,
private ApplicationContextRunner contextRunner = new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(RestClientAutoConfiguration.class,
ReactiveRestClientAutoConfiguration.class, ElasticsearchDataAutoConfiguration.class));
@BeforeEach
@ -69,25 +57,6 @@ class ElasticsearchDataAutoConfigurationTests {
System.clearProperty("es.set.netty.runtime.available.processors");
}
@Test
@SuppressWarnings("deprecation")
void defaultTransportBeansAreRegistered() {
this.contextRunner
.withPropertyValues(
"spring.data.elasticsearch.cluster-nodes:" + elasticsearch.getTcpHost().getHostString() + ":"
+ elasticsearch.getTcpHost().getPort(),
"spring.data.elasticsearch.cluster-name:docker-cluster")
.run((context) -> assertThat(context).hasSingleBean(ElasticsearchTemplate.class)
.hasSingleBean(SimpleElasticsearchMappingContext.class)
.hasSingleBean(ElasticsearchConverter.class));
}
@Test
@SuppressWarnings("deprecation")
void defaultTransportBeansNotRegisteredIfNoTransportClient() {
this.contextRunner.run((context) -> assertThat(context).doesNotHaveBean(ElasticsearchTemplate.class));
}
@Test
void defaultRestBeansRegistered() {
this.contextRunner.run((context) -> assertThat(context).hasSingleBean(ElasticsearchRestTemplate.class)
@ -95,13 +64,6 @@ class ElasticsearchDataAutoConfigurationTests {
.hasSingleBean(ElasticsearchConverter.class));
}
@Test
@SuppressWarnings("deprecation")
void customTransportTemplateShouldBeUsed() {
this.contextRunner.withUserConfiguration(CustomTransportTemplate.class).run((context) -> assertThat(context)
.getBeanNames(ElasticsearchTemplate.class).hasSize(1).contains("elasticsearchTemplate"));
}
@Test
void customRestTemplateShouldBeUsed() {
this.contextRunner.withUserConfiguration(CustomRestTemplate.class).run((context) -> assertThat(context)
@ -115,17 +77,6 @@ class ElasticsearchDataAutoConfigurationTests {
.contains("reactiveElasticsearchTemplate"));
}
@Configuration(proxyBeanMethods = false)
static class CustomTransportTemplate {
@Bean
@SuppressWarnings("deprecation")
ElasticsearchTemplate elasticsearchTemplate() {
return mock(ElasticsearchTemplate.class);
}
}
@Configuration(proxyBeanMethods = false)
static class CustomRestTemplate {

@ -52,8 +52,7 @@ class ElasticsearchRepositoriesAutoConfigurationTests {
.withStartupAttempts(5).withStartupTimeout(Duration.ofMinutes(10));
private ApplicationContextRunner contextRunner = new ApplicationContextRunner()
.withConfiguration(
AutoConfigurations.of(ElasticsearchAutoConfiguration.class, RestClientAutoConfiguration.class,
.withConfiguration(AutoConfigurations.of(RestClientAutoConfiguration.class,
ElasticsearchRepositoriesAutoConfiguration.class, ElasticsearchDataAutoConfiguration.class))
.withPropertyValues("spring.elasticsearch.rest.uris=" + elasticsearch.getHttpHostAddress());

@ -4144,11 +4144,9 @@ Spring Boot supports several clients:
* The official Java "Low Level" and "High Level" REST clients
* The `ReactiveElasticsearchClient` provided by Spring Data Elasticsearch
The transport client is still available but its support has been deprecated in https://github.com/spring-projects/spring-data-elasticsearch[Spring Data Elasticsearch] and Elasticsearch itself.
It will be removed in a future release.
Spring Boot provides a dedicated "`Starter`", `spring-boot-starter-data-elasticsearch`.
The https://github.com/searchbox-io/Jest[Jest] client has been deprecated as well, since both Elasticsearch and Spring Data Elasticsearch provide official support for REST clients.
The https://github.com/searchbox-io/Jest[Jest] client has been deprecated, since both Elasticsearch and Spring Data Elasticsearch provide official support for REST clients.

@ -7,5 +7,7 @@ description = "Starter for using Elasticsearch search and analytics engine and S
dependencies {
api enforcedPlatform(project(':spring-boot-project:spring-boot-dependencies'))
api project(':spring-boot-project:spring-boot-starters:spring-boot-starter')
api 'org.springframework.data:spring-data-elasticsearch'
api ('org.springframework.data:spring-data-elasticsearch') {
exclude group: 'org.elasticsearch.client', module: 'transport'
}
}

Loading…
Cancel
Save