BAEL-2958: Remove spring boot dependencies from Jest demo

This commit is contained in:
Michael Pratt 2019-06-05 14:16:33 +00:00
parent 3bb5ddedb0
commit b31776d89d
3 changed files with 19 additions and 65 deletions

View File

@ -2,52 +2,30 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.5.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.baeldung.jest</groupId> <groupId>com.baeldung.jest</groupId>
<artifactId>jest-demo</artifactId> <artifactId>jest-demo</artifactId>
<version>0.0.1-SNAPSHOT</version> <version>0.0.1-SNAPSHOT</version>
<name>jest-demo</name> <name>jest-demo</name>
<description>Demo project for Spring Boot</description> <description>Demo project for Jest Client for Elasticsearch</description>
<properties> <properties>
<java.version>8</java.version> <java.version>8</java.version>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties> </properties>
<dependencies> <dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency> <dependency>
<groupId>io.searchbox</groupId> <groupId>io.searchbox</groupId>
<artifactId>jest</artifactId> <artifactId>jest</artifactId>
<version>6.3.1</version> <version>6.3.1</version>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency> <dependency>
<groupId>com.fasterxml.jackson.core</groupId> <groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId> <artifactId>jackson-databind</artifactId>
<version>2.9.6</version> <version>2.9.6</version>
</dependency> </dependency>
</dependencies> </dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project> </project>

View File

@ -1,32 +0,0 @@
package com.baeldung.jest;
import io.searchbox.client.JestClient;
import io.searchbox.client.JestClientFactory;
import io.searchbox.client.config.HttpClientConfig;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class JestClientConfiguration {
@Value("${elastic.url:http://localhost:9200}")
private String elasticUrl;
/**
* Create a JEST client bean.
* @return JestClient
*/
@Bean
public JestClient jestClient()
{
JestClientFactory factory = new JestClientFactory();
factory.setHttpClientConfig(
new HttpClientConfig.Builder(elasticUrl)
.multiThreaded(true)
.defaultMaxTotalConnectionPerRoute(2)
.maxTotalConnection(20)
.build());
return factory.getObject();
}
}

View File

@ -5,8 +5,10 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode; import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.databind.node.ObjectNode;
import io.searchbox.client.JestClient; import io.searchbox.client.JestClient;
import io.searchbox.client.JestClientFactory;
import io.searchbox.client.JestResult; import io.searchbox.client.JestResult;
import io.searchbox.client.JestResultHandler; import io.searchbox.client.JestResultHandler;
import io.searchbox.client.config.HttpClientConfig;
import io.searchbox.core.*; import io.searchbox.core.*;
import io.searchbox.indices.CreateIndex; import io.searchbox.indices.CreateIndex;
import io.searchbox.indices.IndicesExists; import io.searchbox.indices.IndicesExists;
@ -15,21 +17,16 @@ import io.searchbox.indices.aliases.ModifyAliases;
import io.searchbox.indices.aliases.RemoveAliasMapping; import io.searchbox.indices.aliases.RemoveAliasMapping;
import io.searchbox.indices.mapping.PutMapping; import io.searchbox.indices.mapping.PutMapping;
import io.searchbox.indices.settings.GetSettings; import io.searchbox.indices.settings.GetSettings;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import java.io.IOException; import java.io.IOException;
import java.util.*; import java.util.*;
@SpringBootApplication
public class JestDemoApplication { public class JestDemoApplication {
public static void main(String[] args) throws IOException { public static void main(String[] args) throws IOException {
ApplicationContext context = SpringApplication.run(JestDemoApplication.class, args);
// Demo the JestClient // Demo the JestClient
JestClient jestClient = context.getBean(JestClient.class); JestClient jestClient = jestClient();
// Check an index // Check an index
JestResult result = jestClient.execute(new IndicesExists.Builder("employees").build()); JestResult result = jestClient.execute(new IndicesExists.Builder("employees").build());
@ -160,4 +157,15 @@ public class JestDemoApplication {
}); });
} }
private static JestClient jestClient()
{
JestClientFactory factory = new JestClientFactory();
factory.setHttpClientConfig(
new HttpClientConfig.Builder("http://localhost:9200")
.multiThreaded(true)
.defaultMaxTotalConnectionPerRoute(2)
.maxTotalConnection(20)
.build());
return factory.getObject();
}
} }