Springboot与Elasticsearch 5.0客户端 - Log4j2错误 [英] Springboot with Elasticsearch 5.0 client - Log4j2 errors

查看:170
本文介绍了Springboot与Elasticsearch 5.0客户端 - Log4j2错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用带有sprintboot应用程序的Elasticsearch 5.0传输客户端。 Elasticsearch 5.0客户端使用log4j2,当我启动我的springboot服务时,ES客户端抛出错误,因为它找不到log4j2类。我尝试了很多组合,但没有运气。
有没有人在springboot应用程序中使用ES 5客户端?

I am trying to use Elasticsearch 5.0 transport client with a sprintboot application. Elasticsearch 5.0 client uses log4j2 and when I launch my springboot service, ES client throws error as it could not find log4j2 classes. I have tried many combinations but no luck yet. Has anybody used ES 5 client within a springboot application?

这是我的pom

<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-logging</artifactId>
                </exclusion>
                <exclusion>
                    <artifactId>logback-classic</artifactId>
                    <groupId>ch.qos.logback</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>log4j-over-slf4j</artifactId>
                    <groupId>org.slf4j</groupId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>log4j-over-slf4j</artifactId>

        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-log4j2</artifactId>
        </dependency>

错误..

 Caused by: java.lang.NoClassDefFoundError: org/apache/logging/log4j/Logger
    at org.elasticsearch.common.logging.Loggers.getLogger(Loggers.java:105)
    at org.elasticsearch.common.logging.Loggers.getLogger(Loggers.java:72)
    at org.elasticsearch.common.component.AbstractComponent.<init>(AbstractComponent.java:37)
    at org.elasticsearch.plugins.PluginsService.<init>(PluginsService.java:110)
    at org.elasticsearch.client.transport.TransportClient.newPluginService(TransportClient.java:81)
    at org.elasticsearch.client.transport.TransportClient.buildTemplate(TransportClient.java:106)
    at org.elasticsearch.client.transport.TransportClient.<init>(TransportClient.java:228)
    at org.elasticsearch.transport.client.PreBuiltTransportClient.<init>(PreBuiltTransportClient.java:69)
    at org.elasticsearch.transport.client.PreBuiltTransportClient.<init>(PreBuiltTransportClient.java:65)
    at com.qualys.service.config.IndexingServiceConfiguration.indexingClient(IndexingServiceConfiguration.java:149)
    at com.qualys.service.config.IndexingServiceConfiguration$$EnhancerBySpringCGLIB$$67ddb691.CGLIB$indexingClient$1(<generated>)
    at com.qualys.service.config.IndexingServiceConfiguration$$EnhancerBySpringCGLIB$$67ddb691$$FastClassBySpringCGLIB$$806f0fda.invoke(<generated>)
    at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
    at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:356)
    at com.qualys.service.config.IndexingServiceConfiguration$$EnhancerBySpringCGLIB$$67ddb691.indexingClient(<generated>)
    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:497)
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162)
    ... 38 more
Caused by: java.lang.ClassNotFoundException: org.apache.logging.log4j.Logger
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 58 more


推荐答案

请添加依赖关系


  1. log4j -api

  2. log4j-core

  3. log4j-slf4j-impl

目前最新版本是2.8。

Currently the latest version is 2.8.

您可以删除log4j-over-slf4j依赖关系,这是旧的Log4j 1.2。

You can remove the log4j-over-slf4j dependency, this is for the old Log4j 1.2.

这篇关于Springboot与Elasticsearch 5.0客户端 - Log4j2错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆