小编典典

Elasticsearch TransportClient NetworkPlugin NoClassDefFoundError

spring-boot

我期待将Elasticsearch集成到Spring Boot Web应用程序中。这是创建我的传输客户端的配置:

@Configuration
public class ElasticsearchConfig {

private TransportClient client;

@Bean
public TransportClient client() throws UnknownHostException{

    Settings settings = Settings.builder()
            .put("client.transport.nodes_sampler_interval", "5s")
            .put("client.transport.sniff", false)
            .put("transport.tcp.compress", true)
            .put("cluster.name", "clusterName")
            .put("xpack.security.transport.ssl.enabled", true)
            .build();

    client = new PreBuiltTransportClient(settings);

    client.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("localhost"), 9300));

    return client;
}

当我启动项目时,出现以下错误,但我不知道为什么:

java.lang.ClassNotFoundException: org.elasticsearch.plugins.NetworkPlugin

我忘了添加依赖吗?

<dependency>
    <groupId>org.springframework.data</groupId>
    <artifactId>spring-data-elasticsearch</artifactId>
</dependency>
<dependency>
    <groupId>org.elasticsearch.client</groupId>
    <artifactId>transport</artifactId>
    <version>5.1.1</version>
</dependency>

希望你能帮我


阅读 410

收藏
2020-05-30

共1个答案

小编典典

我偶然发现了同样的问题。似乎Elasticsearch文档不完整。除了传输客户端依赖性之外,您还需要添加elasticsearch依赖性:

<dependency>
    <groupId>org.elasticsearch</groupId>
    <artifactId>elasticsearch</artifactId>
    <version>5.1.1</version>
</dependency>

您还需要log4j依赖项,但这在Elasticsearch
docs
中已明确说明。

2020-05-30