在我的例子中,我在部署一个 EAR 文件到JBoss EAP 5.2时遇到了同样的“ java.lang.NoSuchMethodError ” 。
日志显示:
SLF4J:您的 slf4j 绑定请求的版本 1.5.6 与 [1.6] 不兼容
日志:(server.log)
2018-11-05 09:59:46,382 ERROR [STDERR] (main) SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
2018-11-05 09:59:46,395 ERROR [STDERR] (main) SLF4J: The requested version 1.5.6 by your slf4j binding is not compatible with [1.6]
2018-11-05 09:59:46,395 ERROR [STDERR] (main) SLF4J: See http://www.slf4j.org/codes.html#version_mismatch for further details.
2018-11-05 09:59:46,402 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[localhost].[/common-scheduling/services]] (main) Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.validation.beanvalidation.LocalValidatorFactoryBean#0': Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: org.slf4j.helpers.MessageFormatter.format(Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/String;
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1512)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:521)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:296)
at
问题:
问题是类路径上有两个不同版本的 slf4j-api jar。(slf4j-log4j12-1.5.6.jar, slf4j-api-1.6.1.jar)
解析度:
- 我运行“mvn dependency:tree”来找到传递依赖的位置。
- 然后,我添加了一个 maven 排除标记来排除不需要的工件版本。
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.5.6</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>