[英]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
請添加依賴項
當前的最新版本是2.8。
您可以刪除log4j-over-slf4j依賴性,這是針對舊Log4j 1.2的。
如果您對version
有dependency
,該怎么辦:
<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。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.