ElasticSearch 6.3.2的Netty依赖问题

时间:2018-08-12 13:32:47

标签: spring spring-boot elasticsearch

我正在使用Spring Boot并尝试与Elasticsearch最新版本6.3.2连接,但是不能,我们是否需要指定任何合适的jar版本

错误:

    Caused by: java.lang.NoClassDefFoundError: io/netty/util/internal/logging/InternalLoggerFactory
    at java.lang.ClassLoader.defineClass1(Native Method) ~[na:1.8.0_161]
    at java.lang.ClassLoader.defineClass(Unknown Source) ~[na:1.8.0_161]
    at java.security.SecureClassLoader.defineClass(Unknown Source) ~[na:1.8.0_161]
    at java.net.URLClassLoader.defineClass(Unknown Source) ~[na:1.8.0_161]
    at java.net.URLClassLoader.access$100(Unknown Source) ~[na:1.8.0_161]
    at java.net.URLClassLoader$1.run(Unknown Source) ~[na:1.8.0_161]
    at java.net.URLClassLoader$1.run(Unknown Source) ~[na:1.8.0_161]
    at java.security.AccessController.doPrivileged(Native Method) ~[na:1.8.0_161]
    at java.net.URLClassLoader.findClass(Unknown Source) ~[na:1.8.0_161]
    at java.lang.ClassLoader.loadClass(Unknown Source) ~[na:1.8.0_161]
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) ~[na:1.8.0_161]
    at java.lang.ClassLoader.loadClass(Unknown Source) ~[na:1.8.0_161]
    at org.elasticsearch.transport.netty4.Netty4Utils.<clinit>(Netty4Utils.java:49) ~[transport-netty4-client-6.3.2.jar:6.3.2]
    at org.elasticsearch.transport.Netty4Plugin.<clinit>(Netty4Plugin.java:48) ~[transport-netty4-client-6.3.2.jar:6.3.2]
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_161]
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) ~[na:1.8.0_161]
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) ~[na:1.8.0_161]
    at java.lang.reflect.Constructor.newInstance(Unknown Source) ~[na:1.8.0_161]
    at org.elasticsearch.plugins.PluginsService.loadPlugin(PluginsService.java:696) ~[elasticsearch-6.3.2.jar:6.3.2]
    at org.elasticsearch.plugins.PluginsService.<init>(PluginsService.java:114) ~[elasticsearch-6.3.2.jar:6.3.2]
    at org.elasticsearch.client.transport.TransportClient.newPluginService(TransportClient.java:107) ~[elasticsearch-6.3.2.jar:6.3.2]
    at org.elasticsearch.client.transport.TransportClient.buildTemplate(TransportClient.java:132) ~[elasticsearch-6.3.2.jar:6.3.2]
    at org.elasticsearch.client.transport.TransportClient.<init>(TransportClient.java:280) ~[elasticsearch-6.3.2.jar:6.3.2]
    at org.elasticsearch.transport.client.PreBuiltTransportClient.<init>(PreBuiltTransportClient.java:128) ~[transport-6.3.2.jar:6.3.2]
    at org.elasticsearch.transport.client.PreBuiltTransportClient.<init>(PreBuiltTransportClient.java:114) ~[transport-6.3.2.jar:6.3.2]
    at org.elasticsearch.transport.client.PreBuiltTransportClient.<init>(PreBuiltTransportClient.java:104) ~[transport-6.3.2.jar:6.3.2]
    at com.techprimers.elastic.standaloneelasticexample.resource.UsersResource.<init>(UsersResource.java:32) ~[classes/:na]
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_161]
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) ~[na:1.8.0_161]
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) ~[na:1.8.0_161]
    at java.lang.reflect.Constructor.newInstance(Unknown Source) ~[na:1.8.0_161]
    at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:170) ~[spring-beans-5.0.5.RELEASE.jar:5.0.5.RELEASE]
    ... 19 common frames omitted
Caused by: java.lang.ClassNotFoundException: io.netty.util.internal.logging.InternalLoggerFactory
    at java.net.URLClassLoader.findClass(Unknown Source) ~[na:1.8.0_161]
    at java.lang.ClassLoader.loadClass(Unknown Source) ~[na:1.8.0_161]
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) ~[na:1.8.0_161]
    at java.lang.ClassLoader.loadClass(Unknown Source) ~[na:1.8.0_161]
    ... 51 common frames omitted

Java代码:

TransportClient client;

        public UsersResource() throws UnknownHostException {
            client = new PreBuiltTransportClient(Settings.EMPTY)
                    .addTransportAddress(new TransportAddress(InetAddress.getByName("localhost"), 9300));
            //client.close();

        }

下面我给出了POM的配置

<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.elastic</groupId>
<artifactId>standalone-elastic-example</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>standalone-elastic-example</name>
<description>Demo project for Spring Boot</description>
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.1.RELEASE</version>
    <relativePath /> <!-- lookup parent from repository -->
</parent>
<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <java.version>1.8</java.version>
    <elasticsearch.version>6.3.2</elasticsearch.version>
</properties>
<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-elasticsearch</artifactId>
    </dependency>
    <dependency>
        <groupId>org.elasticsearch</groupId>
        <artifactId>elasticsearch</artifactId>
    </dependency>
    <dependency>
        <groupId>org.elasticsearch.client</groupId>
        <artifactId>transport</artifactId>
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-api</artifactId>
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-core</artifactId>
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-web</artifactId>
    </dependency>
</dependencies>

我想念任何依赖吗?

是什么导致此问题无法连接。如果有更多信息,请告诉我。

谢谢。

1 个答案:

答案 0 :(得分:0)

这可能无法解决您的NoClassDefFoundError,但您可能应该开始使用“ Java High Level REST Client”,因为elasticsearch计划在Elasticsearch 7.0中弃用TransportClient并在8.0中将其完全删除。因此,最好使用Java High Level REST客户端而不是传输客户端。

更多详细信息可用here