#509 - Favor Spring Boot auto-configuration in Elasticsearch example.
This commit is contained in:
@@ -1,19 +1,13 @@
|
||||
# Spring Data Elasticsearch - Reactive Examples
|
||||
|
||||
The `ReactiveElasticsearchClient` is a non official driver based on `WebClient`.
|
||||
The `ReactiveElasticsearchClient` is a client based on `WebClient`.
|
||||
It uses the request/response objects provided by the Elasticsearch core project.
|
||||
Calls are directly operated on the reactive stack, not wrapping async (thread pool bound) responses into reactive types.
|
||||
|
||||
````java
|
||||
class ApplicationConfiguration extends AbstractReactiveElasticsearchConfiguration {
|
||||
|
||||
@Bean
|
||||
@Override
|
||||
public ReactiveElasticsearchClient reactiveElasticsearchClient() {
|
||||
return ReactiveRestClients.create(ClientConfiguration.localhost());
|
||||
}
|
||||
}
|
||||
````
|
||||
```java
|
||||
@SpringBootApplication
|
||||
class ApplicationConfiguration {}
|
||||
```
|
||||
|
||||
The `ReactiveElasticsearchClient` can be used with the `ReactiveElasticsearchOperations` and `ReactiveElasticsearchRepository`.
|
||||
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
/*
|
||||
* Copyright 2019 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,
|
||||
@@ -27,33 +27,21 @@ import org.elasticsearch.action.admin.indices.create.CreateIndexRequest;
|
||||
import org.elasticsearch.client.RequestOptions;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.data.elasticsearch.client.ClientConfiguration;
|
||||
import org.springframework.data.elasticsearch.client.RestClients;
|
||||
import org.springframework.data.elasticsearch.client.reactive.ReactiveElasticsearchClient;
|
||||
import org.springframework.data.elasticsearch.client.reactive.ReactiveRestClients;
|
||||
import org.springframework.data.elasticsearch.config.AbstractReactiveElasticsearchConfiguration;
|
||||
import org.springframework.data.elasticsearch.core.ReactiveElasticsearchOperations;
|
||||
import org.springframework.data.elasticsearch.core.geo.GeoPoint;
|
||||
import org.springframework.data.elasticsearch.repository.config.EnableReactiveElasticsearchRepositories;
|
||||
|
||||
/**
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
@Configuration
|
||||
@EnableReactiveElasticsearchRepositories
|
||||
class ApplicationConfiguration extends AbstractReactiveElasticsearchConfiguration {
|
||||
@SpringBootApplication
|
||||
class ApplicationConfiguration {
|
||||
|
||||
@Autowired ReactiveElasticsearchOperations operations;
|
||||
@Autowired ConferenceRepository repository;
|
||||
|
||||
@Bean
|
||||
@Override
|
||||
public ReactiveElasticsearchClient reactiveElasticsearchClient() {
|
||||
return ReactiveRestClients.create(ClientConfiguration.localhost());
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
public void insertDataSample() {
|
||||
|
||||
|
||||
@@ -1,3 +1 @@
|
||||
# Uncomment both entries to connect with local elasticsearch cluster
|
||||
#spring.data.elasticsearch.clusterName=elasticsearch
|
||||
#spring.data.elasticsearch.clusterNodes=localhost:9300
|
||||
spring.data.elasticsearch.client.reactive.endpoints=localhost:9200
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
/*
|
||||
* Copyright 2019 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,
|
||||
@@ -32,13 +32,14 @@ import org.springframework.data.elasticsearch.core.ReactiveElasticsearchOperatio
|
||||
import org.springframework.data.elasticsearch.core.query.Criteria;
|
||||
import org.springframework.data.elasticsearch.core.query.CriteriaQuery;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
/**
|
||||
* Test case to show Spring Data Elasticsearch functionality.
|
||||
*
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = ApplicationConfiguration.class)
|
||||
public class ReactiveElasticsearchOperationsTest {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user