繁体   English   中英

使用Elasticsearch 5.0客户端的Springboot-Log4j2错误

[英]Springboot with Elasticsearch 5.0 client - Log4j2 errors

我试图将Elasticsearch 5.0 transport客户端与sprintboot应用程序一起使用。 Elasticsearch 5.0客户端使用log4j2,当我启动springboot服务时,ES客户端抛出错误,因为它找不到log4j2类。 我尝试了许多组合,但还没有碰运气。 有人在springboot应用程序中使用过ES 5客户端吗?

这是我的宝

<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的核心
  3. log4j的-SLF4J-IMPL

当前的最新版本是2.8。

您可以删除log4j-over-slf4j依赖性,这是针对旧Log4j 1.2的。

如果您对versiondependency ,该怎么办:

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

资源

我正在将Spring Boot与ES客户端一起使用。 尝试以下依赖项

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


        <!--elastic search client-->
        <dependency>
            <groupId>org.elasticsearch.client</groupId>
            <artifactId>transport</artifactId>
            <version>5.0.1</version>
        </dependency>

        <!--log 4j-->
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-api</artifactId>
            <version>2.6.2</version>
        </dependency>
    </dependencies> 

同样在pom.xml的属性中添加以下内容

<properties>
        <elasticsearch.version>5.0.0</elasticsearch.version>
</properties>

检查此链接,显然尚未完成Springboot版本,尚不支持弹性搜索5.0.0版本,您可能希望将es版本降级为2.xx.xx。

https://github.com/spring-projects/spring-data-elasticsearch/wiki/Spring-Data-Elasticsearch---Spring-Boot---version-matrix

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM