栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > .Net

ES6.8.1 Could not initialize class org.elasticsearch.transport.Netty3Plugin

.Net 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

ES6.8.1 Could not initialize class org.elasticsearch.transport.Netty3Plugin

ES6.8.1集成springBoot报错:nested exception is java.lang.NoClassDefFoundError: Could not initialize class org.elasticsearch.transport.Netty3Plugin

第一步:配置pom文件依赖


        
            org.elasticsearch
            elasticsearch
            6.8.1
        
        
            org.elasticsearch.client
            x-pack-transport
            6.8.1
        

        
            org.elasticsearch.plugin
            transport-netty4-client
            6.8.1
        
        
            io.netty
            netty-all
            4.1.13.Final
        

第二步:配置文件添加配置属性

第三步:注意这是ES6.8.1加密插件链接配置

第四步:创建ES配置实例化客户端

package com.mobartisan.oms.historyalarm.configurer;

import org.apache.commons.lang.StringUtils;
import org.elasticsearch.client.Client;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.TransportAddress;
import org.elasticsearch.xpack.client.PreBuiltXPackTransportClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.io.File;
import java.net.InetSocketAddress;
import java.net.URL;

@Configuration
public class ElasticSearchConfig {

    private static final Logger logger = LoggerFactory.getLogger(ElasticSearchConfig.class);
    @Value("${elasticsearch.cluster.nodes}")
    private String clusterNodes;

    @Value("${elasticsearch.cluster.name}")
    private String clusterName;

    @Value("${elasticsearch.auth}")
    private String securityUser;

    @Value("${elasticsearch.secretKey}")
    private String secretKey;

    @Bean
    public Client client(){
        URL resource = this.getClass().getResource("/");
        TransportClient client = null;
        if(resource!=null){
            File file = new File(resource.getPath());
            Settings settings = Settings.builder().put("cluster.name", clusterName)
//                    .put("client.transport.sniff", true)
                    .put("xpack.security.user", securityUser)
                    .put("xpack.ssl.key", file+"/"+secretKey+"/elasticsearch.key")
                    .put("xpack.ssl.certificate", file+"/"+secretKey+"/elasticsearch.crt")
                    .put("xpack.ssl.certificate_authorities", file+"/"+secretKey+"/ca.crt")
                    .put("xpack.security.transport.ssl.enabled", "true").build();

            client = new PreBuiltXPackTransportClient(settings);
            try {
                if (StringUtils.isNotEmpty(clusterNodes)) {
                    for (String node : clusterNodes.split(",")) {
                        String[] nodeInfo = node.split(":");
                        client.addTransportAddress(new TransportAddress(new InetSocketAddress(nodeInfo[0],Integer.parseInt(nodeInfo[1]))));
                    }
                }
            } catch (Exception e) {
                logger.error("elastic search connection errr:"+e);
            }
            logger.info("连接ES成功");
        }
        return client;
    }
}

报出异常:

Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.elasticsearch.client.Client]: Factory method 'client' threw exception; nested exception is java.lang.NoClassDefFoundError: Could not initialize class org.elasticsearch.transport.Netty3Plugin
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189)
	at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588)
	... 65 more
Caused by: java.lang.NoClassDefFoundError: Could not initialize class org.elasticsearch.transport.Netty3Plugin
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
	at org.elasticsearch.plugins.PluginsService.loadPlugin(PluginsService.java:609)
	at org.elasticsearch.plugins.PluginsService.(PluginsService.java:119)
	at org.elasticsearch.client.transport.TransportClient.newPluginService(TransportClient.java:110)
	at org.elasticsearch.client.transport.TransportClient.buildTemplate(TransportClient.java:135)
	at org.elasticsearch.client.transport.TransportClient.(TransportClient.java:288)
	at org.elasticsearch.transport.client.PreBuiltTransportClient.(PreBuiltTransportClient.java:133)
	at org.elasticsearch.xpack.client.PreBuiltXPackTransportClient.(PreBuiltXPackTransportClient.java:47)
	at org.elasticsearch.xpack.client.PreBuiltXPackTransportClient.(PreBuiltXPackTransportClient.java:42)
	at org.elasticsearch.xpack.client.PreBuiltXPackTransportClient.(PreBuiltXPackTransportClient.java:38)
	at com.mobartisan.oms.historyalarm.configurer.ElasticSearchConfig.client(ElasticSearchConfig.java:49)
	at com.mobartisan.oms.historyalarm.configurer.ElasticSearchConfig$$EnhancerBySpringCGLIB$$4862b273.CGLIB$client$0()
	at com.mobartisan.oms.historyalarm.configurer.ElasticSearchConfig$$EnhancerBySpringCGLIB$$4862b273$$FastClassBySpringCGLIB$$2d824a57.invoke()
	at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
	at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:358)
	at com.mobartisan.oms.historyalarm.configurer.ElasticSearchConfig$$EnhancerBySpringCGLIB$$4862b273.client()
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162)
	... 66 more

排查异常问题:



问题发现:表面是引入了ES插件6.8.1版本,实质其中的客户端jar使用的还是5.6.8版本,所以导致启动时匹配到的版本较低。

解决问题:

排除x-pack-transport:6.8.1插件jar下的transport:5.6.8客户端jar。
新增6.8.1的客户端transport的jar。

例如:

        
            org.elasticsearch
            elasticsearch
            6.8.1
        
        
            org.elasticsearch.client
            x-pack-transport
            
                
                    org.elasticsearch.client
                    transport
                
            
            6.8.1
        

        
            org.elasticsearch.client
            transport
            6.8.1
        

        
            org.elasticsearch.plugin
            transport-netty4-client
            6.8.1
        
        
            io.netty
            netty-all
            4.1.13.Final
        

重新启动,问题解决。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/907673.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号