Elasticsearch TransportClient NetworkPlugin NoClassDefFoundError
Elasticsearch TransportClient NetworkPlugin NoClassDefFoundError
我期待将 Elasticsearch 集成到 Spring 引导 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>
希望你能帮助我
对我来说,elastic search 在 pom 中似乎有错误的依赖版本
<properties>
<log4j.version>2.6.2</log4j.version>
</properties>
<dependencies>
<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
<version>5.1.1</version>
</dependency>
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>transport</artifactId>
<version>5.1.1</version>
<exclusions>
<exclusion>
<artifactId>elasticsearch</artifactId>
<groupId>org.elasticsearch</groupId></exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>${log4j.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>${log4j.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-web</artifactId>
<version>${log4j.version}</version>
</dependency>
尝试将版本替换为5.1.1
好吧,它看起来还需要 log4j ?!
此致,
诺拉比斯
我刚遇到同样的问题。似乎 Elasticsearch 文档不完整。除了transport client依赖,还需要添加elasticsearch依赖:
<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
<version>5.1.1</version>
</dependency>
您还需要 log4j 依赖项,但这在 Elasticsearch docs.
中有明确说明
在ElasticsearchGithub页面this issue中有说明,SpringBoot starter管理了一些默认的依赖,定义了5.1.1以下的ElasticSearch默认版本,所以没有这个class.
您可以在自己的 pom 中显式定义 属性 以覆盖其定义。
<properties>
<elasticsearch.version>5.1.1</elasticsearch.version>
</properties>
希望对您有所帮助。
我期待将 Elasticsearch 集成到 Spring 引导 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>
希望你能帮助我
对我来说,elastic search 在 pom 中似乎有错误的依赖版本
<properties>
<log4j.version>2.6.2</log4j.version>
</properties>
<dependencies>
<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
<version>5.1.1</version>
</dependency>
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>transport</artifactId>
<version>5.1.1</version>
<exclusions>
<exclusion>
<artifactId>elasticsearch</artifactId>
<groupId>org.elasticsearch</groupId></exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>${log4j.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>${log4j.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-web</artifactId>
<version>${log4j.version}</version>
</dependency>
尝试将版本替换为5.1.1 好吧,它看起来还需要 log4j ?!
此致, 诺拉比斯
我刚遇到同样的问题。似乎 Elasticsearch 文档不完整。除了transport client依赖,还需要添加elasticsearch依赖:
<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
<version>5.1.1</version>
</dependency>
您还需要 log4j 依赖项,但这在 Elasticsearch docs.
中有明确说明在ElasticsearchGithub页面this issue中有说明,SpringBoot starter管理了一些默认的依赖,定义了5.1.1以下的ElasticSearch默认版本,所以没有这个class.
您可以在自己的 pom 中显式定义 属性 以覆盖其定义。
<properties>
<elasticsearch.version>5.1.1</elasticsearch.version>
</properties>
希望对您有所帮助。