parent
6a2ff3f02a
commit
05ef0818f8
|
@ -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);
|
||||
|
|
|
@ -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<String, String> defaults = new LinkedHashMap<String, String>();
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -105,6 +105,7 @@
|
|||
<jetty.version>9.2.15.v20160210</jetty.version>
|
||||
<jetty-jsp.version>2.2.0.v201112011158</jetty-jsp.version>
|
||||
<jmustache.version>1.12</jmustache.version>
|
||||
<jna.version>4.2.2</jna.version>
|
||||
<joda-time.version>2.9.2</joda-time.version>
|
||||
<jolokia.version>1.3.3</jolokia.version>
|
||||
<jooq.version>3.7.2</jooq.version>
|
||||
|
@ -951,6 +952,11 @@
|
|||
<artifactId>mysql-connector-java</artifactId>
|
||||
<version>${mysql.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.java.dev.jna</groupId>
|
||||
<artifactId>jna</artifactId>
|
||||
<version>${jna.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.sf.ehcache</groupId>
|
||||
<artifactId>ehcache</artifactId>
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -26,6 +26,13 @@
|
|||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-elasticsearch</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>net.java.dev.jna</groupId>
|
||||
<artifactId>jna</artifactId>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
|
|
|
@ -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
|
Loading…
Reference in New Issue