web-dev-qa-db-fra.com

Causé par: Java.lang.ClassNotFoundException: org.elasticsearch.transport.Netty3Plugin

J'utilise la version Spring Boot 2.0.3 et j'ai un problème lors de l'instanciation de org.elasticsearch.client.Client. Mon code:

Client client = new PreBuiltTransportClient(Settings.builder()
                .put("cluster.name", clustername)
                .build())
                .addTransportAddress(
new InetSocketTransportAddress(InetAddress.getByName(Host), port)
);

Ce code me donne l'erreur:

Caused by: Java.lang.NoClassDefFoundError: org/elasticsearch/transport/Netty3Plugin
at org.elasticsearch.transport.client.PreBuiltTransportClient.<clinit>(PreBuiltTransportClient.Java:91) ~[transport-5.6.10.jar:5.6.10]
at kz.icode.idmatrix.config.ElasticsearchConfiguration.client(ElasticsearchConfiguration.Java:56) ~[classes/:na]
at kz.icode.idmatrix.config.ElasticsearchConfiguration$$EnhancerBySpringCGLIB$$7e53ae93.CGLIB$client$0(<generated>) ~[classes/:na]
at kz.icode.idmatrix.config.ElasticsearchConfiguration$$EnhancerBySpringCGLIB$$7e53ae93$$FastClassBySpringCGLIB$$fef36179.invoke(<generated>) ~[classes/:na]
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.Java:228) ~[spring-core-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.Java:361) ~[spring-context-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at kz.icode.idmatrix.config.ElasticsearchConfiguration$$EnhancerBySpringCGLIB$$7e53ae93.client(<generated>) ~[classes/:na]
at Sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_171]
at Sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.Java:62) ~[na:1.8.0_171]
at Sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.Java:43) ~[na:1.8.0_171]
at Java.lang.reflect.Method.invoke(Method.Java:498) ~[na:1.8.0_171]
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.Java:154) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
... 99 common frames omitted

J'utilise org.elasticsearch:elasticsearch:5.6.10 et org.elasticsearch.client:client:5.6.10.

5
Abzelhan

Toutes les dépendances ne sont pas satisfaites en ajoutant uniquement spring-boot-starter-data-elasticsearch.

Il est nécessaire de définir explicitement toutes les dépendances restantes:

    <dependency>
        <groupId>org.elasticsearch.client</groupId>
        <artifactId>transport</artifactId>
        <version>${elasticsearch.version}</version>
    </dependency>

    <dependency>
        <groupId>org.elasticsearch.plugin</groupId>
        <artifactId>transport-netty4-client</artifactId>
        <version>${elasticsearch.version}</version>
    </dependency>

Si vous avez déclaré un parent, probablement <version> la balise peut être omise.

16
Abzelhan
<dependency> 
    <groupId>org.elasticsearch.client</groupId> 
    <artifactId>transport</artifactId> 
</dependency>

C'est résolu pour moi.

0
An Nguyen