#509 - Favor Spring Boot auto-configuration in Elasticsearch example.

This commit is contained in:
Mark Paluch
2020-06-16 15:16:29 +02:00
parent 3d88c50655
commit d92e7feabc
11 changed files with 37 additions and 75 deletions

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2014-2018 the original author or authors.
* Copyright 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
* http://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,
@@ -22,22 +22,21 @@ import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import org.elasticsearch.client.Client;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.elasticsearch.client.NodeClientFactoryBean;
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
import org.springframework.data.elasticsearch.core.geo.GeoPoint;
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
/**
* @author Artur Konczak
* @author Oliver Gierke
* @author Christoph Strobl
*/
@Configuration
@EnableElasticsearchRepositories
@SpringBootApplication
class ApplicationConfiguration {
@Autowired ElasticsearchOperations operations;
@@ -56,7 +55,7 @@ class ApplicationConfiguration {
}
@Bean
public ElasticsearchTemplate elasticsearchTemplate(Client client) throws Exception {
public ElasticsearchTemplate elasticsearchTemplate(Client client) {
return new ElasticsearchTemplate(client);
}

View File

@@ -1,3 +1 @@
# Uncomment both entries to connect with local elasticsearch cluster
#spring.data.elasticsearch.clusterName=elasticsearch
#spring.data.elasticsearch.clusterNodes=localhost:9300
#spring.elasticsearch.rest.uris=http://localhost:9200

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2014-2018 the original author or authors.
* Copyright 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
* http://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,
@@ -15,13 +15,14 @@
*/
package example.springdata.elasticsearch.conference;
import static org.assertj.core.api.Assertions.*;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.List;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
@@ -33,8 +34,6 @@ import org.springframework.data.elasticsearch.core.query.Criteria;
import org.springframework.data.elasticsearch.core.query.CriteriaQuery;
import org.springframework.test.context.junit4.SpringRunner;
import static org.assertj.core.api.Assertions.*;
/**
* Test case to show Spring Data Elasticsearch functionality.
*