版本健全性检查(Spring/SLF4J) [英] Version Sanity Check (Spring/SLF4J)
本文介绍了版本健全性检查(Spring/SLF4J)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在Tomcat上部署Spring Boot应用程序。但不知何故,我得到了:
Unexpected problem occured during version sanity check
Reported exception:
java.lang.AbstractMethodError: org.apache.logging.slf4j.SLF4JServiceProvider.getRequestedApiVersion()Ljava/lang/String;
at org.slf4j.LoggerFactory.versionSanityCheck(LoggerFactory.java:297)
at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:141)
at org.slf4j.LoggerFactory.getProvider(LoggerFactory.java:421)
at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:407)
at io.micrometer.core.util.internal.logging.Slf4JLoggerFactory.<init>(Slf4JLoggerFactory.java:49)
at io.micrometer.core.util.internal.logging.Slf4JLoggerFactory.<clinit>(Slf4JLoggerFactory.java:46)
at io.micrometer.core.util.internal.logging.InternalLoggerFactory.newDefaultFactory(InternalLoggerFactory.java:60)
at io.micrometer.core.util.internal.logging.InternalLoggerFactory.getDefaultFactory(InternalLoggerFactory.java:76)
at io.micrometer.core.util.internal.logging.InternalLoggerFactory.getInstance(InternalLoggerFactory.java:108)
at io.micrometer.core.util.internal.logging.InternalLoggerFactory.getInstance(InternalLoggerFactory.java:98)
at io.micrometer.core.instrument.binder.jvm.JvmGcMetrics.<clinit>(JvmGcMetrics.java:61)
at org.springframework.boot.actuate.autoconfigure.metrics.JvmMetricsAutoConfiguration.jvmGcMetrics(JvmMetricsAutoConfiguration.java:48)
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:154)
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:653)
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:486)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1352)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1195)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:582)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
我在一个通用的类加载器中有几个SLF4J/Log4J2 JAR,用于其他一些Web应用程序。
点赞:
log4j-api-2.14.1.jar
log4j-core-2.14.1.jar
log4j-over-slf4j-2.0.0-alpha5.jar
log4j-slf4j18-impl-2.14.1.jar
slf4j-api-2.0.0-alpha5.jar
我认为这是与slf4j罐子和春季战争的罐子的冲突。因此,我从Spring应用程序中排除了所有sllf4j项,认为它会从公共加载器中挑选类。但我得到了上面的错误。应用程序启动正常,没有任何问题。但不确定如何摆脱这一点。我的Spring应用程序的pom的最后一个依赖项部分如下所示:
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-to-slf4j</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>jul-to-slf4j</artifactId>
</exclusion>
<exclusion>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bootstrap</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-core -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
</dependencies>
推荐答案
似乎在log4j-slf4j18-impl
库中发现了拼写错误。
slf4j-api:2.0.0-alpha5
中的LoggerFactory尝试从提供程序(source)获取请求的API版本:
String requested = PROVIDER.getRequestedApiVersion();
但实际实现似乎只有一个名为getRequesteApiVersion的方法
我鼓励您在Apachesissue tracker中打开一个关于这方面的问题。编辑: 我在APACHE问题跟踪器(https://issues.apache.org/jira/browse/LOG4J2-3139)中发现了类似的问题。 基于该信息,slf4J对2.0版本进行了非向后兼容的更改(将getRequesteApiVersion方法更改为getRequestedApiVersion)。由于slf4j目前处于阿尔法版本,因此只有在slf4j有了稳定的版本之后,apache才会修复这个问题。
您可以尝试的是为slf4j指定另一个提供程序,或者隐式使用旧版本的slf4j。
这篇关于版本健全性检查(Spring/SLF4J)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文