Skip to content

Commit 05ef081

Browse files
committed
Polish contribution
Closes spring-projectsgh-5511
1 parent 6a2ff3f commit 05ef081

File tree

8 files changed

+51
-7
lines changed

8 files changed

+51
-7
lines changed

spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/HealthIndicatorAutoConfigurationTests.java

+2
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,7 @@ public void notJmsHealthIndicator() {
393393
@Test
394394
public void elasticSearchHealthIndicator() {
395395
EnvironmentTestUtils.addEnvironment(this.context,
396+
"spring.data.elasticsearch.properties.path.home:target",
396397
"management.health.diskspace.enabled:false");
397398
this.context.register(ElasticsearchAutoConfiguration.class,
398399
ManagementServerProperties.class, HealthIndicatorAutoConfiguration.class);
@@ -409,6 +410,7 @@ public void elasticSearchHealthIndicator() {
409410
public void notElasticSearchHealthIndicator() {
410411
EnvironmentTestUtils.addEnvironment(this.context,
411412
"management.health.elasticsearch.enabled:false",
413+
"spring.data.elasticsearch.properties.path.home:target",
412414
"management.health.diskspace.enabled:false");
413415
this.context.register(ElasticsearchAutoConfiguration.class,
414416
ManagementServerProperties.class, HealthIndicatorAutoConfiguration.class);

spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchAutoConfiguration.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
package org.springframework.boot.autoconfigure.data.elasticsearch;
1818

19-
import java.io.File;
2019
import java.util.Collections;
2120
import java.util.LinkedHashMap;
2221
import java.util.Map;
@@ -63,7 +62,7 @@ public class ElasticsearchAutoConfiguration implements DisposableBean {
6362
Map<String, String> defaults = new LinkedHashMap<String, String>();
6463
defaults.put("http.enabled", String.valueOf(false));
6564
defaults.put("node.local", String.valueOf(true));
66-
defaults.put("path.home", new File(System.getProperty("java.io.tmpdir"), "elastic-home").getAbsolutePath());
65+
defaults.put("path.home", System.getProperty("user.dir"));
6766
DEFAULTS = Collections.unmodifiableMap(defaults);
6867
}
6968

spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchAutoConfigurationTests.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ public void close() {
5656
public void createNodeClientWithDefaults() {
5757
this.context = new AnnotationConfigApplicationContext();
5858
EnvironmentTestUtils.addEnvironment(this.context,
59-
"spring.data.elasticsearch.properties.foo.bar:baz");
59+
"spring.data.elasticsearch.properties.foo.bar:baz",
60+
"spring.data.elasticsearch.properties.path.home:target");
6061
this.context.register(PropertyPlaceholderAutoConfiguration.class,
6162
ElasticsearchAutoConfiguration.class);
6263
this.context.refresh();
@@ -72,6 +73,7 @@ public void createNodeClientWithOverrides() {
7273
this.context = new AnnotationConfigApplicationContext();
7374
EnvironmentTestUtils.addEnvironment(this.context,
7475
"spring.data.elasticsearch.properties.foo.bar:baz",
76+
"spring.data.elasticsearch.properties.path.home:target",
7577
"spring.data.elasticsearch.properties.node.local:false",
7678
"spring.data.elasticsearch.properties.node.data:true",
7779
"spring.data.elasticsearch.properties.http.enabled:true");
@@ -104,7 +106,8 @@ public void createTransportClient() throws Exception {
104106
// a port and check the exception
105107
this.context = new AnnotationConfigApplicationContext();
106108
EnvironmentTestUtils.addEnvironment(this.context,
107-
"spring.data.elasticsearch.cluster-nodes:localhost");
109+
"spring.data.elasticsearch.cluster-nodes:localhost",
110+
"spring.data.elasticsearch.properties.path.home:target");
108111
this.context.register(PropertyPlaceholderAutoConfiguration.class,
109112
ElasticsearchAutoConfiguration.class);
110113
this.thrown.expect(BeanCreationException.class);

spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchRepositoriesAutoConfigurationTests.java

+9
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.springframework.boot.autoconfigure.data.elasticsearch.city.City;
2727
import org.springframework.boot.autoconfigure.data.elasticsearch.city.CityRepository;
2828
import org.springframework.boot.autoconfigure.data.empty.EmptyDataPackage;
29+
import org.springframework.boot.test.util.EnvironmentTestUtils;
2930
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
3031
import org.springframework.context.annotation.Configuration;
3132
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
@@ -49,6 +50,7 @@ public void close() {
4950
@Test
5051
public void testDefaultRepositoryConfiguration() throws Exception {
5152
this.context = new AnnotationConfigApplicationContext();
53+
addElasticsearchProperties(this.context);
5254
this.context.register(TestConfiguration.class,
5355
ElasticsearchAutoConfiguration.class,
5456
ElasticsearchRepositoriesAutoConfiguration.class,
@@ -62,6 +64,7 @@ public void testDefaultRepositoryConfiguration() throws Exception {
6264
@Test
6365
public void testNoRepositoryConfiguration() throws Exception {
6466
this.context = new AnnotationConfigApplicationContext();
67+
addElasticsearchProperties(this.context);
6568
this.context.register(EmptyConfiguration.class,
6669
ElasticsearchAutoConfiguration.class,
6770
ElasticsearchRepositoriesAutoConfiguration.class,
@@ -74,6 +77,7 @@ public void testNoRepositoryConfiguration() throws Exception {
7477
@Test
7578
public void doesNotTriggerDefaultRepositoryDetectionIfCustomized() {
7679
this.context = new AnnotationConfigApplicationContext();
80+
addElasticsearchProperties(this.context);
7781
this.context.register(CustomizedConfiguration.class,
7882
ElasticsearchAutoConfiguration.class,
7983
ElasticsearchRepositoriesAutoConfiguration.class,
@@ -83,6 +87,11 @@ public void doesNotTriggerDefaultRepositoryDetectionIfCustomized() {
8387
assertThat(this.context.getBean(CityElasticsearchDbRepository.class)).isNotNull();
8488
}
8589

90+
private void addElasticsearchProperties(AnnotationConfigApplicationContext context) {
91+
EnvironmentTestUtils.addEnvironment(context,
92+
"spring.data.elasticsearch.properties.path.home:target");
93+
}
94+
8695
@Configuration
8796
@TestAutoConfigurationPackage(City.class)
8897
protected static class TestConfiguration {

spring-boot-dependencies/pom.xml

+6
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@
105105
<jetty.version>9.2.15.v20160210</jetty.version>
106106
<jetty-jsp.version>2.2.0.v201112011158</jetty-jsp.version>
107107
<jmustache.version>1.12</jmustache.version>
108+
<jna.version>4.2.2</jna.version>
108109
<joda-time.version>2.9.2</joda-time.version>
109110
<jolokia.version>1.3.3</jolokia.version>
110111
<jooq.version>3.7.2</jooq.version>
@@ -951,6 +952,11 @@
951952
<artifactId>mysql-connector-java</artifactId>
952953
<version>${mysql.version}</version>
953954
</dependency>
955+
<dependency>
956+
<groupId>net.java.dev.jna</groupId>
957+
<artifactId>jna</artifactId>
958+
<version>${jna.version}</version>
959+
</dependency>
954960
<dependency>
955961
<groupId>net.sf.ehcache</groupId>
956962
<artifactId>ehcache</artifactId>

spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc

+16-3
Original file line numberDiff line numberDiff line change
@@ -3214,11 +3214,24 @@ dependencies in a convenient way.
32143214
[[boot-features-connecting-to-elasticsearch]]
32153215
==== Connecting to Elasticsearch
32163216
You can inject an auto-configured `ElasticsearchTemplate` or Elasticsearch `Client`
3217-
instance as you would any other Spring Bean. By default the instance will attempt to
3218-
connect to a local in-memory server (a `NodeClient` in Elasticsearch terms), but you can
3219-
switch to a remote server (i.e. a `TransportClient`) by setting
3217+
instance as you would any other Spring Bean. By default the instance will embed a
3218+
local in-memory server (a `Node` in ElasticSearch terms) and use the current working
3219+
directory as the home directory for the server. In this setup, the first thing to do
3220+
is to tell ElasticSearch were to store its files:
3221+
3222+
[source,properties,indent=0]
3223+
----
3224+
spring.data.elasticsearch.properties.path.home=/foo/bar
3225+
----
3226+
3227+
Alternatively, you can switch to a remote server (i.e. a `TransportClient`) by setting
32203228
`spring.data.elasticsearch.cluster-nodes` to a comma-separated '`host:port`' list.
32213229

3230+
[source,properties,indent=0]
3231+
----
3232+
spring.data.elasticsearch.cluster-nodes=localhost:9300
3233+
----
3234+
32223235
[source,java,indent=0]
32233236
----
32243237
@Component

spring-boot-samples/spring-boot-sample-data-elasticsearch/pom.xml

+7
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@
2626
<groupId>org.springframework.boot</groupId>
2727
<artifactId>spring-boot-starter-data-elasticsearch</artifactId>
2828
</dependency>
29+
30+
<dependency>
31+
<groupId>net.java.dev.jna</groupId>
32+
<artifactId>jna</artifactId>
33+
<scope>runtime</scope>
34+
</dependency>
35+
2936
<dependency>
3037
<groupId>org.springframework.boot</groupId>
3138
<artifactId>spring-boot-starter-test</artifactId>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#
2+
# Home directory of the embedded elastic instance. Default to the
3+
# current working directory.
4+
#
5+
spring.data.elasticsearch.properties.path.home=target/elastic

0 commit comments

Comments
 (0)