From 34eb3695e4ec1393e82f6995b4dfac3f9e79ce9a Mon Sep 17 00:00:00 2001 From: Quinten De Swaef Date: Mon, 4 Apr 2016 22:49:38 +0200 Subject: [PATCH 1/7] Allow Tomcat's minimum threads to be configured via the environment Closes gh-5572 --- .../autoconfigure/web/ServerProperties.java | 32 +++++++++++++++++++ .../web/ServerPropertiesTests.java | 8 +++++ .../appendix-application-properties.adoc | 1 + 3 files changed, 41 insertions(+) diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java index 80d61fcb9a5..849bfb695af 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java @@ -580,6 +580,11 @@ public class ServerProperties */ private int maxThreads = 0; // Number of threads in protocol handler + /** + * Minimum amount of worker threads. + */ + private int minSpareThreads = 0; //Number of minimum spare threads in protocol handler + /** * Maximum size in bytes of the HTTP message header. */ @@ -598,6 +603,14 @@ public class ServerProperties this.maxThreads = maxThreads; } + public int getMinSpareThreads() { + return minSpareThreads; + } + + public void setMinSpareThreads(int minSpareThreads) { + this.minSpareThreads = minSpareThreads; + } + public int getMaxHttpHeaderSize() { return this.maxHttpHeaderSize; } @@ -684,6 +697,9 @@ public class ServerProperties if (this.maxThreads > 0) { customizeMaxThreads(factory); } + if (this.minSpareThreads > 0) { + customizeMinThreads(factory); + } if (this.maxHttpHeaderSize > 0) { customizeMaxHttpHeaderSize(factory); } @@ -747,6 +763,22 @@ public class ServerProperties }); } + @SuppressWarnings("rawtypes") + private void customizeMinThreads(TomcatEmbeddedServletContainerFactory factory) { + factory.addConnectorCustomizers(new TomcatConnectorCustomizer() { + @Override + public void customize(Connector connector) { + + ProtocolHandler handler = connector.getProtocolHandler(); + if (handler instanceof AbstractProtocol) { + AbstractProtocol protocol = (AbstractProtocol) handler; + protocol.setMinSpareThreads(Tomcat.this.minSpareThreads); + } + + } + }); + } + @SuppressWarnings("rawtypes") private void customizeMaxHttpHeaderSize( TomcatEmbeddedServletContainerFactory factory) { diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ServerPropertiesTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ServerPropertiesTests.java index 9a0a97bc917..71ea172c6a0 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ServerPropertiesTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ServerPropertiesTests.java @@ -258,6 +258,14 @@ public class ServerPropertiesTests { assertThat(this.properties.getTomcat().getMaxHttpHeaderSize()).isEqualTo(9999); } + @Test + public void testCustomizeTomcatMinSpareThreads() throws Exception { + Map map = new HashMap(); + map.put("server.tomcat.min-spare-threads", "10"); + bindProperties(map); + assertThat(this.properties.getTomcat().getMinSpareThreads()).isEqualTo(10); + } + @Test public void customizeTomcatDisplayName() throws Exception { Map map = new HashMap(); diff --git a/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc b/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc index afad598c8b0..029523d2ffc 100644 --- a/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc +++ b/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc @@ -204,6 +204,7 @@ content into your application; rather pick only the properties that you need. 172\\.3[0-1]{1}\\.\\d{1,3}\\.\\d{1,3} # regular expression matching trusted IP addresses. server.tomcat.max-http-header-size=0 # Maximum size in bytes of the HTTP message header. server.tomcat.max-threads=0 # Maximum amount of worker threads. + server.tomcat.min-spare-threads=0 # Maximum amount of worker threads. server.tomcat.port-header=X-Forwarded-Port # Name of the HTTP header used to override the original port value. server.tomcat.protocol-header= # Header that holds the incoming protocol, usually named "X-Forwarded-Proto". server.tomcat.protocol-header-https-value=https # Value of the protocol header that indicates that the incoming request uses SSL. From 487f7310fdd2e77fb6908b475d26a478e762ff4b Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Tue, 5 Apr 2016 11:00:44 +0100 Subject: [PATCH 2/7] Polish contribution --- .../boot/autoconfigure/web/ServerProperties.java | 5 +++-- .../boot/autoconfigure/web/ServerPropertiesTests.java | 1 + .../src/main/asciidoc/appendix-application-properties.adoc | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java index 849bfb695af..aeaad83b98a 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java @@ -72,6 +72,7 @@ import org.springframework.util.StringUtils; * @author Ivan Sopov * @author Marcos Barbero * @author Eddú Meléndez + * @author Quinten De Swaef */ @ConfigurationProperties(prefix = "server", ignoreUnknownFields = true) public class ServerProperties @@ -583,7 +584,7 @@ public class ServerProperties /** * Minimum amount of worker threads. */ - private int minSpareThreads = 0; //Number of minimum spare threads in protocol handler + private int minSpareThreads = 0; // Minimum spare threads in protocol handler /** * Maximum size in bytes of the HTTP message header. @@ -604,7 +605,7 @@ public class ServerProperties } public int getMinSpareThreads() { - return minSpareThreads; + return this.minSpareThreads; } public void setMinSpareThreads(int minSpareThreads) { diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ServerPropertiesTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ServerPropertiesTests.java index 71ea172c6a0..a72fcc6b1a3 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ServerPropertiesTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ServerPropertiesTests.java @@ -62,6 +62,7 @@ import static org.mockito.Mockito.verify; * @author Andy Wilkinson * @author Phillip Webb * @author Eddú Meléndez + * @author Quinten De Swaef */ public class ServerPropertiesTests { diff --git a/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc b/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc index 029523d2ffc..57a96cde136 100644 --- a/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc +++ b/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc @@ -204,7 +204,7 @@ content into your application; rather pick only the properties that you need. 172\\.3[0-1]{1}\\.\\d{1,3}\\.\\d{1,3} # regular expression matching trusted IP addresses. server.tomcat.max-http-header-size=0 # Maximum size in bytes of the HTTP message header. server.tomcat.max-threads=0 # Maximum amount of worker threads. - server.tomcat.min-spare-threads=0 # Maximum amount of worker threads. + server.tomcat.min-spare-threads=0 # Minimum amount of worker threads. server.tomcat.port-header=X-Forwarded-Port # Name of the HTTP header used to override the original port value. server.tomcat.protocol-header= # Header that holds the incoming protocol, usually named "X-Forwarded-Proto". server.tomcat.protocol-header-https-value=https # Value of the protocol header that indicates that the incoming request uses SSL. From ab15d73bc81841086803b2e01fb4c7af323a549e Mon Sep 17 00:00:00 2001 From: Johnny Lim Date: Tue, 5 Apr 2016 14:40:30 +0900 Subject: [PATCH 3/7] Remove unused unsatisfiedDependency.getInjectionPoint() call Closes gh-5575 --- .../analyzer/NoUniqueBeanDefinitionExceptionFailureAnalyzer.java | 1 - 1 file changed, 1 deletion(-) diff --git a/spring-boot/src/main/java/org/springframework/boot/diagnostics/analyzer/NoUniqueBeanDefinitionExceptionFailureAnalyzer.java b/spring-boot/src/main/java/org/springframework/boot/diagnostics/analyzer/NoUniqueBeanDefinitionExceptionFailureAnalyzer.java index 6c648a40b11..e6d795bfbd1 100644 --- a/spring-boot/src/main/java/org/springframework/boot/diagnostics/analyzer/NoUniqueBeanDefinitionExceptionFailureAnalyzer.java +++ b/spring-boot/src/main/java/org/springframework/boot/diagnostics/analyzer/NoUniqueBeanDefinitionExceptionFailureAnalyzer.java @@ -64,7 +64,6 @@ class NoUniqueBeanDefinitionExceptionFailureAnalyzer message.append(String.format("%s required a single bean, but %d were found:%n", getConsumerDescription(unsatisfiedDependency), beanNames.length)); for (String beanName : beanNames) { - unsatisfiedDependency.getInjectionPoint(); try { BeanDefinition beanDefinition = this.beanFactory .getMergedBeanDefinition(beanName); From 0db118c1898c6772798d1108ad8f218ac3f3b14b Mon Sep 17 00:00:00 2001 From: dreis Date: Thu, 31 Mar 2016 19:30:40 +0200 Subject: [PATCH 4/7] Deprecate Undertow container's constructors that have a port parameter Closes gh-5546 --- .../UndertowEmbeddedServletContainer.java | 90 +++++++++++++++++-- ...dertowEmbeddedServletContainerFactory.java | 3 +- 2 files changed, 86 insertions(+), 7 deletions(-) diff --git a/spring-boot/src/main/java/org/springframework/boot/context/embedded/undertow/UndertowEmbeddedServletContainer.java b/spring-boot/src/main/java/org/springframework/boot/context/embedded/undertow/UndertowEmbeddedServletContainer.java index 678702dd42e..6e9b56fb199 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/embedded/undertow/UndertowEmbeddedServletContainer.java +++ b/spring-boot/src/main/java/org/springframework/boot/context/embedded/undertow/UndertowEmbeddedServletContainer.java @@ -87,20 +87,100 @@ public class UndertowEmbeddedServletContainer implements EmbeddedServletContaine private boolean started = false; + /** + * Create a new {@link UndertowEmbeddedServletContainer} instance. + * @param builder the builder + * @param manager the deployment manager + * @param contextPath root the context path + * @param port the port to listen on (not used) + * @param autoStart if the server should be started + * @param compression compression configuration + * @deprecated as of 1.4 in favor of using constructors without port argument + */ + @Deprecated public UndertowEmbeddedServletContainer(Builder builder, DeploymentManager manager, String contextPath, int port, boolean autoStart, Compression compression) { - this(builder, manager, contextPath, port, false, autoStart, compression); + this(builder, manager, contextPath, false, autoStart, compression); } + /** + * Create a new {@link UndertowEmbeddedServletContainer} instance. + * @param builder the builder + * @param manager the deployment manager + * @param contextPath root the context path + * @param port the port to listen on (not used) + * @param useForwardHeaders if x-forward headers should be used + * @param autoStart if the server should be started + * @param compression compression configuration + * @deprecated as of 1.4 in favor of using constructors without port argument + */ + @Deprecated public UndertowEmbeddedServletContainer(Builder builder, DeploymentManager manager, String contextPath, int port, boolean useForwardHeaders, boolean autoStart, Compression compression) { - this(builder, manager, contextPath, port, useForwardHeaders, autoStart, + this(builder, manager, contextPath, useForwardHeaders, autoStart, compression, null); + } + + /** + * Create a new {@link UndertowEmbeddedServletContainer} instance. + * @param builder the builder + * @param manager the deployment manager + * @param contextPath root the context path + * @param port the port to listen on (not used) + * @param useForwardHeaders if x-forward headers should be used + * @param autoStart if the server should be started + * @param compression compression configuration + * @param serverHeader string to be used in http header + * @deprecated as of 1.4 in favor of using constructors without port argument + */ + @Deprecated + public UndertowEmbeddedServletContainer(Builder builder, DeploymentManager manager, + String contextPath, int port, boolean useForwardHeaders, boolean autoStart, + Compression compression, String serverHeader) { + this(builder, manager, contextPath, useForwardHeaders, autoStart, compression, serverHeader); + } + + /** + * Create a new {@link UndertowEmbeddedServletContainer} instance. + * @param builder the builder + * @param manager the deployment manager + * @param contextPath root the context path + * @param autoStart if the server should be started + * @param compression compression configuration + */ + public UndertowEmbeddedServletContainer(Builder builder, DeploymentManager manager, + String contextPath, boolean autoStart, Compression compression) { + this(builder, manager, contextPath, false, autoStart, compression); + } + + /** + * Create a new {@link UndertowEmbeddedServletContainer} instance. + * @param builder the builder + * @param manager the deployment manager + * @param contextPath root the context path + * @param useForwardHeaders if x-forward headers should be used + * @param autoStart if the server should be started + * @param compression compression configuration + */ + public UndertowEmbeddedServletContainer(Builder builder, DeploymentManager manager, + String contextPath, boolean useForwardHeaders, boolean autoStart, + Compression compression) { + this(builder, manager, contextPath, useForwardHeaders, autoStart, compression, null); } + /** + * Create a new {@link UndertowEmbeddedServletContainer} instance. + * @param builder the builder + * @param manager the deployment manager + * @param contextPath root the context path + * @param useForwardHeaders if x-forward headers should be used + * @param autoStart if the server should be started + * @param compression compression configuration + * @param serverHeader string to be used in http header + */ public UndertowEmbeddedServletContainer(Builder builder, DeploymentManager manager, - String contextPath, int port, boolean useForwardHeaders, boolean autoStart, + String contextPath, boolean useForwardHeaders, boolean autoStart, Compression compression, String serverHeader) { this.builder = builder; this.manager = manager; @@ -231,10 +311,10 @@ public class UndertowEmbeddedServletContainer implements EmbeddedServletContaine } private Port getPortFromChannel(BoundChannel channel) { - String protocol = ReflectionUtils.findField(channel.getClass(), "ssl") != null - ? "https" : "http"; SocketAddress socketAddress = channel.getLocalAddress(); if (socketAddress instanceof InetSocketAddress) { + String protocol = ReflectionUtils.findField(channel.getClass(), "ssl") != null + ? "https" : "http"; return new Port(((InetSocketAddress) socketAddress).getPort(), protocol); } return null; diff --git a/spring-boot/src/main/java/org/springframework/boot/context/embedded/undertow/UndertowEmbeddedServletContainerFactory.java b/spring-boot/src/main/java/org/springframework/boot/context/embedded/undertow/UndertowEmbeddedServletContainerFactory.java index 02ac6cb5fc9..2ab91ecc784 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/embedded/undertow/UndertowEmbeddedServletContainerFactory.java +++ b/spring-boot/src/main/java/org/springframework/boot/context/embedded/undertow/UndertowEmbeddedServletContainerFactory.java @@ -501,8 +501,7 @@ public class UndertowEmbeddedServletContainerFactory protected UndertowEmbeddedServletContainer getUndertowEmbeddedServletContainer( Builder builder, DeploymentManager manager, int port) { return new UndertowEmbeddedServletContainer(builder, manager, getContextPath(), - port, isUseForwardHeaders(), port >= 0, getCompression(), - getServerHeader()); + isUseForwardHeaders(), port >= 0, getCompression(), getServerHeader()); } @Override From 42a2d2da37932f5cbdf0aecb5b07fa8f3476112c Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Tue, 5 Apr 2016 11:26:29 +0100 Subject: [PATCH 5/7] Polish contribution --- .../UndertowEmbeddedServletContainer.java | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/spring-boot/src/main/java/org/springframework/boot/context/embedded/undertow/UndertowEmbeddedServletContainer.java b/spring-boot/src/main/java/org/springframework/boot/context/embedded/undertow/UndertowEmbeddedServletContainer.java index 6e9b56fb199..b7bab2cb4b6 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/embedded/undertow/UndertowEmbeddedServletContainer.java +++ b/spring-boot/src/main/java/org/springframework/boot/context/embedded/undertow/UndertowEmbeddedServletContainer.java @@ -61,6 +61,7 @@ import org.springframework.util.StringUtils; * @author Ivan Sopov * @author Andy Wilkinson * @author Eddú Meléndez + * @author Christoph Dreis * @since 1.2.0 * @see UndertowEmbeddedServletContainerFactory */ @@ -95,7 +96,8 @@ public class UndertowEmbeddedServletContainer implements EmbeddedServletContaine * @param port the port to listen on (not used) * @param autoStart if the server should be started * @param compression compression configuration - * @deprecated as of 1.4 in favor of using constructors without port argument + * @deprecated as of 1.4 in favor of + * {@link #UndertowEmbeddedServletContainer(Builder, DeploymentManager, String, boolean, Compression)} */ @Deprecated public UndertowEmbeddedServletContainer(Builder builder, DeploymentManager manager, @@ -112,13 +114,14 @@ public class UndertowEmbeddedServletContainer implements EmbeddedServletContaine * @param useForwardHeaders if x-forward headers should be used * @param autoStart if the server should be started * @param compression compression configuration - * @deprecated as of 1.4 in favor of using constructors without port argument + * @deprecated as of 1.4 in favor of + * {@link #UndertowEmbeddedServletContainer(Builder, DeploymentManager, String, boolean, boolean, Compression)} */ @Deprecated public UndertowEmbeddedServletContainer(Builder builder, DeploymentManager manager, String contextPath, int port, boolean useForwardHeaders, boolean autoStart, Compression compression) { - this(builder, manager, contextPath, useForwardHeaders, autoStart, compression, null); + this(builder, manager, contextPath, useForwardHeaders, autoStart, compression); } /** @@ -131,13 +134,15 @@ public class UndertowEmbeddedServletContainer implements EmbeddedServletContaine * @param autoStart if the server should be started * @param compression compression configuration * @param serverHeader string to be used in http header - * @deprecated as of 1.4 in favor of using constructors without port argument + * @deprecated as of 1.4 in favor of + * {@link #UndertowEmbeddedServletContainer(Builder, DeploymentManager, String, boolean, boolean, Compression, String)} */ @Deprecated public UndertowEmbeddedServletContainer(Builder builder, DeploymentManager manager, String contextPath, int port, boolean useForwardHeaders, boolean autoStart, Compression compression, String serverHeader) { - this(builder, manager, contextPath, useForwardHeaders, autoStart, compression, serverHeader); + this(builder, manager, contextPath, useForwardHeaders, autoStart, compression, + serverHeader); } /** @@ -165,8 +170,8 @@ public class UndertowEmbeddedServletContainer implements EmbeddedServletContaine public UndertowEmbeddedServletContainer(Builder builder, DeploymentManager manager, String contextPath, boolean useForwardHeaders, boolean autoStart, Compression compression) { - this(builder, manager, contextPath, useForwardHeaders, autoStart, - compression, null); + this(builder, manager, contextPath, useForwardHeaders, autoStart, compression, + null); } /** From 6a2ff3f02ac083665cf8c47a2d71de6db52f2c5e Mon Sep 17 00:00:00 2001 From: Huang YunKun Date: Wed, 30 Mar 2016 13:02:01 +0000 Subject: [PATCH 6/7] Upgrade elasticsearch to 2.2.0 Closes gh-5443 --- .../HealthIndicatorAutoConfigurationTests.java | 4 ---- .../health/ElasticsearchHealthIndicatorTests.java | 6 +++--- .../elasticsearch/ElasticsearchAutoConfiguration.java | 6 ++++-- .../ElasticsearchAutoConfigurationTests.java | 10 ++-------- ...lasticsearchRepositoriesAutoConfigurationTests.java | 10 ---------- spring-boot-dependencies/pom.xml | 2 +- .../SampleElasticsearchApplicationTests.java | 8 +------- 7 files changed, 11 insertions(+), 35 deletions(-) diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/HealthIndicatorAutoConfigurationTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/HealthIndicatorAutoConfigurationTests.java index c15ec2a2917..572cb796119 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/HealthIndicatorAutoConfigurationTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/HealthIndicatorAutoConfigurationTests.java @@ -393,8 +393,6 @@ public class HealthIndicatorAutoConfigurationTests { @Test public void elasticSearchHealthIndicator() { EnvironmentTestUtils.addEnvironment(this.context, - "spring.data.elasticsearch.properties.path.data:target/data", - "spring.data.elasticsearch.properties.path.logs:target/logs", "management.health.diskspace.enabled:false"); this.context.register(ElasticsearchAutoConfiguration.class, ManagementServerProperties.class, HealthIndicatorAutoConfiguration.class); @@ -411,8 +409,6 @@ public class HealthIndicatorAutoConfigurationTests { public void notElasticSearchHealthIndicator() { EnvironmentTestUtils.addEnvironment(this.context, "management.health.elasticsearch.enabled:false", - "spring.data.elasticsearch.properties.path.data:target/data", - "spring.data.elasticsearch.properties.path.logs:target/logs", "management.health.diskspace.enabled:false"); this.context.register(ElasticsearchAutoConfiguration.class, ManagementServerProperties.class, HealthIndicatorAutoConfiguration.class); diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/ElasticsearchHealthIndicatorTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/ElasticsearchHealthIndicatorTests.java index f6034ee20a8..22faa933da5 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/ElasticsearchHealthIndicatorTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/ElasticsearchHealthIndicatorTests.java @@ -23,13 +23,13 @@ import org.elasticsearch.ElasticsearchException; import org.elasticsearch.ElasticsearchTimeoutException; import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest; import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; -import org.elasticsearch.action.admin.cluster.health.ClusterHealthStatus; import org.elasticsearch.action.support.PlainActionFuture; import org.elasticsearch.client.AdminClient; import org.elasticsearch.client.Client; import org.elasticsearch.client.ClusterAdminClient; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.block.ClusterBlocks; +import org.elasticsearch.cluster.health.ClusterHealthStatus; import org.elasticsearch.cluster.node.DiscoveryNodes; import org.elasticsearch.cluster.routing.RoutingTable; import org.junit.Before; @@ -176,9 +176,9 @@ public class ElasticsearchHealthIndicatorTests { private StubClusterHealthResponse(ClusterHealthStatus status) { super("test-cluster", new String[0], - new ClusterState(null, 0, null, RoutingTable.builder().build(), + new ClusterState(null, 0, null, null, RoutingTable.builder().build(), DiscoveryNodes.builder().build(), - ClusterBlocks.builder().build(), null)); + ClusterBlocks.builder().build(), null, false)); this.status = status; } diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchAutoConfiguration.java index 2e286cdd4b9..304fefea8ba 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchAutoConfiguration.java @@ -16,6 +16,7 @@ package org.springframework.boot.autoconfigure.data.elasticsearch; +import java.io.File; import java.util.Collections; import java.util.LinkedHashMap; import java.util.Map; @@ -26,7 +27,7 @@ import org.apache.commons.logging.LogFactory; import org.elasticsearch.client.Client; import org.elasticsearch.client.transport.TransportClient; import org.elasticsearch.common.lease.Releasable; -import org.elasticsearch.common.settings.ImmutableSettings; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.node.Node; import org.elasticsearch.node.NodeBuilder; @@ -62,6 +63,7 @@ public class ElasticsearchAutoConfiguration implements DisposableBean { Map defaults = new LinkedHashMap(); defaults.put("http.enabled", String.valueOf(false)); defaults.put("node.local", String.valueOf(true)); + defaults.put("path.home", new File(System.getProperty("java.io.tmpdir"), "elastic-home").getAbsolutePath()); DEFAULTS = Collections.unmodifiableMap(defaults); } @@ -95,7 +97,7 @@ public class ElasticsearchAutoConfiguration implements DisposableBean { } private Client createNodeClient() throws Exception { - ImmutableSettings.Builder settings = ImmutableSettings.settingsBuilder(); + Settings.Builder settings = Settings.settingsBuilder(); for (Map.Entry entry : DEFAULTS.entrySet()) { if (!this.properties.getProperties().containsKey(entry.getKey())) { settings.put(entry.getKey(), entry.getValue()); diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchAutoConfigurationTests.java index c65a31df272..a06def87c96 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchAutoConfigurationTests.java @@ -56,9 +56,7 @@ public class ElasticsearchAutoConfigurationTests { public void createNodeClientWithDefaults() { this.context = new AnnotationConfigApplicationContext(); EnvironmentTestUtils.addEnvironment(this.context, - "spring.data.elasticsearch.properties.foo.bar:baz", - "spring.data.elasticsearch.properties.path.data:target/data", - "spring.data.elasticsearch.properties.path.logs:target/logs"); + "spring.data.elasticsearch.properties.foo.bar:baz"); this.context.register(PropertyPlaceholderAutoConfiguration.class, ElasticsearchAutoConfiguration.class); this.context.refresh(); @@ -74,8 +72,6 @@ public class ElasticsearchAutoConfigurationTests { this.context = new AnnotationConfigApplicationContext(); EnvironmentTestUtils.addEnvironment(this.context, "spring.data.elasticsearch.properties.foo.bar:baz", - "spring.data.elasticsearch.properties.path.data:target/data", - "spring.data.elasticsearch.properties.path.logs:target/logs", "spring.data.elasticsearch.properties.node.local:false", "spring.data.elasticsearch.properties.node.data:true", "spring.data.elasticsearch.properties.http.enabled:true"); @@ -108,9 +104,7 @@ public class ElasticsearchAutoConfigurationTests { // a port and check the exception this.context = new AnnotationConfigApplicationContext(); EnvironmentTestUtils.addEnvironment(this.context, - "spring.data.elasticsearch.cluster-nodes:localhost", - "spring.data.elasticsearch.properties.path.data:target/data", - "spring.data.elasticsearch.properties.path.logs:target/logs"); + "spring.data.elasticsearch.cluster-nodes:localhost"); this.context.register(PropertyPlaceholderAutoConfiguration.class, ElasticsearchAutoConfiguration.class); this.thrown.expect(BeanCreationException.class); diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchRepositoriesAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchRepositoriesAutoConfigurationTests.java index d9d9a13a2f9..f7ec5a14267 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchRepositoriesAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchRepositoriesAutoConfigurationTests.java @@ -26,7 +26,6 @@ import org.springframework.boot.autoconfigure.data.alt.elasticsearch.CityElastic import org.springframework.boot.autoconfigure.data.elasticsearch.city.City; import org.springframework.boot.autoconfigure.data.elasticsearch.city.CityRepository; import org.springframework.boot.autoconfigure.data.empty.EmptyDataPackage; -import org.springframework.boot.test.util.EnvironmentTestUtils; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Configuration; import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories; @@ -50,7 +49,6 @@ public class ElasticsearchRepositoriesAutoConfigurationTests { @Test public void testDefaultRepositoryConfiguration() throws Exception { this.context = new AnnotationConfigApplicationContext(); - addElasticsearchProperties(this.context); this.context.register(TestConfiguration.class, ElasticsearchAutoConfiguration.class, ElasticsearchRepositoriesAutoConfiguration.class, @@ -64,7 +62,6 @@ public class ElasticsearchRepositoriesAutoConfigurationTests { @Test public void testNoRepositoryConfiguration() throws Exception { this.context = new AnnotationConfigApplicationContext(); - addElasticsearchProperties(this.context); this.context.register(EmptyConfiguration.class, ElasticsearchAutoConfiguration.class, ElasticsearchRepositoriesAutoConfiguration.class, @@ -77,7 +74,6 @@ public class ElasticsearchRepositoriesAutoConfigurationTests { @Test public void doesNotTriggerDefaultRepositoryDetectionIfCustomized() { this.context = new AnnotationConfigApplicationContext(); - addElasticsearchProperties(this.context); this.context.register(CustomizedConfiguration.class, ElasticsearchAutoConfiguration.class, ElasticsearchRepositoriesAutoConfiguration.class, @@ -87,12 +83,6 @@ public class ElasticsearchRepositoriesAutoConfigurationTests { assertThat(this.context.getBean(CityElasticsearchDbRepository.class)).isNotNull(); } - private void addElasticsearchProperties(AnnotationConfigApplicationContext context) { - EnvironmentTestUtils.addEnvironment(context, - "spring.data.elasticsearch.properties.path.data:target/data", - "spring.data.elasticsearch.properties.path.logs:target/logs"); - } - @Configuration @TestAutoConfigurationPackage(City.class) protected static class TestConfiguration { diff --git a/spring-boot-dependencies/pom.xml b/spring-boot-dependencies/pom.xml index 1d3b6f823cd..ebd8f51b743 100644 --- a/spring-boot-dependencies/pom.xml +++ b/spring-boot-dependencies/pom.xml @@ -70,7 +70,7 @@ 1.50.2 3.2.1 2.3.23 - 1.7.5 + 2.2.0 8.2.0 3.0.0 1.12 diff --git a/spring-boot-samples/spring-boot-sample-data-elasticsearch/src/test/java/sample/data/elasticsearch/SampleElasticsearchApplicationTests.java b/spring-boot-samples/spring-boot-sample-data-elasticsearch/src/test/java/sample/data/elasticsearch/SampleElasticsearchApplicationTests.java index 3940a565a29..c94efe24e9e 100644 --- a/spring-boot-samples/spring-boot-sample-data-elasticsearch/src/test/java/sample/data/elasticsearch/SampleElasticsearchApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-data-elasticsearch/src/test/java/sample/data/elasticsearch/SampleElasticsearchApplicationTests.java @@ -33,19 +33,13 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Artur Konczak */ public class SampleElasticsearchApplicationTests { - - private static final String[] PROPERTIES = { - "spring.data.elasticsearch.properties.path.data:target/data", - "spring.data.elasticsearch.properties.path.logs:target/logs" }; - @Rule public OutputCapture outputCapture = new OutputCapture(); @Test public void testDefaultSettings() throws Exception { try { - new SpringApplicationBuilder(SampleElasticsearchApplication.class) - .properties(PROPERTIES).run(); + new SpringApplicationBuilder(SampleElasticsearchApplication.class).run(); } catch (IllegalStateException ex) { if (serverNotRunning(ex)) { From 05ef0818f852420945ba903512e93a82a02cf41e Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Tue, 5 Apr 2016 12:31:45 +0200 Subject: [PATCH 7/7] Polish contribution Closes gh-5511 --- ...HealthIndicatorAutoConfigurationTests.java | 2 ++ .../ElasticsearchAutoConfiguration.java | 3 +-- .../ElasticsearchAutoConfigurationTests.java | 7 +++++-- ...rchRepositoriesAutoConfigurationTests.java | 9 +++++++++ spring-boot-dependencies/pom.xml | 6 ++++++ .../main/asciidoc/spring-boot-features.adoc | 19 ++++++++++++++++--- .../pom.xml | 7 +++++++ .../src/main/resources/application.properties | 5 +++++ 8 files changed, 51 insertions(+), 7 deletions(-) create mode 100644 spring-boot-samples/spring-boot-sample-data-elasticsearch/src/main/resources/application.properties diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/HealthIndicatorAutoConfigurationTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/HealthIndicatorAutoConfigurationTests.java index 572cb796119..7d9f2d55797 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/HealthIndicatorAutoConfigurationTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/HealthIndicatorAutoConfigurationTests.java @@ -393,6 +393,7 @@ public class HealthIndicatorAutoConfigurationTests { @Test public void elasticSearchHealthIndicator() { EnvironmentTestUtils.addEnvironment(this.context, + "spring.data.elasticsearch.properties.path.home:target", "management.health.diskspace.enabled:false"); this.context.register(ElasticsearchAutoConfiguration.class, ManagementServerProperties.class, HealthIndicatorAutoConfiguration.class); @@ -409,6 +410,7 @@ public class HealthIndicatorAutoConfigurationTests { public void notElasticSearchHealthIndicator() { EnvironmentTestUtils.addEnvironment(this.context, "management.health.elasticsearch.enabled:false", + "spring.data.elasticsearch.properties.path.home:target", "management.health.diskspace.enabled:false"); this.context.register(ElasticsearchAutoConfiguration.class, ManagementServerProperties.class, HealthIndicatorAutoConfiguration.class); diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchAutoConfiguration.java index 304fefea8ba..c35f3a75ac5 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchAutoConfiguration.java @@ -16,7 +16,6 @@ package org.springframework.boot.autoconfigure.data.elasticsearch; -import java.io.File; import java.util.Collections; import java.util.LinkedHashMap; import java.util.Map; @@ -63,7 +62,7 @@ public class ElasticsearchAutoConfiguration implements DisposableBean { Map defaults = new LinkedHashMap(); defaults.put("http.enabled", String.valueOf(false)); defaults.put("node.local", String.valueOf(true)); - defaults.put("path.home", new File(System.getProperty("java.io.tmpdir"), "elastic-home").getAbsolutePath()); + defaults.put("path.home", System.getProperty("user.dir")); DEFAULTS = Collections.unmodifiableMap(defaults); } diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchAutoConfigurationTests.java index a06def87c96..320c490c5eb 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchAutoConfigurationTests.java @@ -56,7 +56,8 @@ public class ElasticsearchAutoConfigurationTests { public void createNodeClientWithDefaults() { this.context = new AnnotationConfigApplicationContext(); EnvironmentTestUtils.addEnvironment(this.context, - "spring.data.elasticsearch.properties.foo.bar:baz"); + "spring.data.elasticsearch.properties.foo.bar:baz", + "spring.data.elasticsearch.properties.path.home:target"); this.context.register(PropertyPlaceholderAutoConfiguration.class, ElasticsearchAutoConfiguration.class); this.context.refresh(); @@ -72,6 +73,7 @@ public class ElasticsearchAutoConfigurationTests { this.context = new AnnotationConfigApplicationContext(); EnvironmentTestUtils.addEnvironment(this.context, "spring.data.elasticsearch.properties.foo.bar:baz", + "spring.data.elasticsearch.properties.path.home:target", "spring.data.elasticsearch.properties.node.local:false", "spring.data.elasticsearch.properties.node.data:true", "spring.data.elasticsearch.properties.http.enabled:true"); @@ -104,7 +106,8 @@ public class ElasticsearchAutoConfigurationTests { // a port and check the exception this.context = new AnnotationConfigApplicationContext(); EnvironmentTestUtils.addEnvironment(this.context, - "spring.data.elasticsearch.cluster-nodes:localhost"); + "spring.data.elasticsearch.cluster-nodes:localhost", + "spring.data.elasticsearch.properties.path.home:target"); this.context.register(PropertyPlaceholderAutoConfiguration.class, ElasticsearchAutoConfiguration.class); this.thrown.expect(BeanCreationException.class); diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchRepositoriesAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchRepositoriesAutoConfigurationTests.java index f7ec5a14267..03fc86bbf2a 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchRepositoriesAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchRepositoriesAutoConfigurationTests.java @@ -26,6 +26,7 @@ import org.springframework.boot.autoconfigure.data.alt.elasticsearch.CityElastic import org.springframework.boot.autoconfigure.data.elasticsearch.city.City; import org.springframework.boot.autoconfigure.data.elasticsearch.city.CityRepository; import org.springframework.boot.autoconfigure.data.empty.EmptyDataPackage; +import org.springframework.boot.test.util.EnvironmentTestUtils; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Configuration; import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories; @@ -49,6 +50,7 @@ public class ElasticsearchRepositoriesAutoConfigurationTests { @Test public void testDefaultRepositoryConfiguration() throws Exception { this.context = new AnnotationConfigApplicationContext(); + addElasticsearchProperties(this.context); this.context.register(TestConfiguration.class, ElasticsearchAutoConfiguration.class, ElasticsearchRepositoriesAutoConfiguration.class, @@ -62,6 +64,7 @@ public class ElasticsearchRepositoriesAutoConfigurationTests { @Test public void testNoRepositoryConfiguration() throws Exception { this.context = new AnnotationConfigApplicationContext(); + addElasticsearchProperties(this.context); this.context.register(EmptyConfiguration.class, ElasticsearchAutoConfiguration.class, ElasticsearchRepositoriesAutoConfiguration.class, @@ -74,6 +77,7 @@ public class ElasticsearchRepositoriesAutoConfigurationTests { @Test public void doesNotTriggerDefaultRepositoryDetectionIfCustomized() { this.context = new AnnotationConfigApplicationContext(); + addElasticsearchProperties(this.context); this.context.register(CustomizedConfiguration.class, ElasticsearchAutoConfiguration.class, ElasticsearchRepositoriesAutoConfiguration.class, @@ -83,6 +87,11 @@ public class ElasticsearchRepositoriesAutoConfigurationTests { assertThat(this.context.getBean(CityElasticsearchDbRepository.class)).isNotNull(); } + private void addElasticsearchProperties(AnnotationConfigApplicationContext context) { + EnvironmentTestUtils.addEnvironment(context, + "spring.data.elasticsearch.properties.path.home:target"); + } + @Configuration @TestAutoConfigurationPackage(City.class) protected static class TestConfiguration { diff --git a/spring-boot-dependencies/pom.xml b/spring-boot-dependencies/pom.xml index ebd8f51b743..6d6f4fb0ddf 100644 --- a/spring-boot-dependencies/pom.xml +++ b/spring-boot-dependencies/pom.xml @@ -105,6 +105,7 @@ 9.2.15.v20160210 2.2.0.v201112011158 1.12 + 4.2.2 2.9.2 1.3.3 3.7.2 @@ -951,6 +952,11 @@ mysql-connector-java ${mysql.version} + + net.java.dev.jna + jna + ${jna.version} + net.sf.ehcache ehcache diff --git a/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc b/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc index 72b0eee3576..bb3af00c980 100644 --- a/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc +++ b/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc @@ -3214,11 +3214,24 @@ dependencies in a convenient way. [[boot-features-connecting-to-elasticsearch]] ==== Connecting to Elasticsearch You can inject an auto-configured `ElasticsearchTemplate` or Elasticsearch `Client` -instance as you would any other Spring Bean. By default the instance will attempt to -connect to a local in-memory server (a `NodeClient` in Elasticsearch terms), but you can -switch to a remote server (i.e. a `TransportClient`) by setting +instance as you would any other Spring Bean. By default the instance will embed a +local in-memory server (a `Node` in ElasticSearch terms) and use the current working +directory as the home directory for the server. In this setup, the first thing to do +is to tell ElasticSearch were to store its files: + +[source,properties,indent=0] +---- + spring.data.elasticsearch.properties.path.home=/foo/bar +---- + +Alternatively, you can switch to a remote server (i.e. a `TransportClient`) by setting `spring.data.elasticsearch.cluster-nodes` to a comma-separated '`host:port`' list. +[source,properties,indent=0] +---- + spring.data.elasticsearch.cluster-nodes=localhost:9300 +---- + [source,java,indent=0] ---- @Component diff --git a/spring-boot-samples/spring-boot-sample-data-elasticsearch/pom.xml b/spring-boot-samples/spring-boot-sample-data-elasticsearch/pom.xml index f9978cf308f..f6cbc4408eb 100644 --- a/spring-boot-samples/spring-boot-sample-data-elasticsearch/pom.xml +++ b/spring-boot-samples/spring-boot-sample-data-elasticsearch/pom.xml @@ -26,6 +26,13 @@ org.springframework.boot spring-boot-starter-data-elasticsearch + + + net.java.dev.jna + jna + runtime + + org.springframework.boot spring-boot-starter-test diff --git a/spring-boot-samples/spring-boot-sample-data-elasticsearch/src/main/resources/application.properties b/spring-boot-samples/spring-boot-sample-data-elasticsearch/src/main/resources/application.properties new file mode 100644 index 00000000000..8ed51d8ad79 --- /dev/null +++ b/spring-boot-samples/spring-boot-sample-data-elasticsearch/src/main/resources/application.properties @@ -0,0 +1,5 @@ +# +# Home directory of the embedded elastic instance. Default to the +# current working directory. +# +spring.data.elasticsearch.properties.path.home=target/elastic \ No newline at end of file