Java 为什么我在运行 Jetty 时在 LocationAwareLogger 上不断收到 NoSuchMethodError?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19071485/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Why do I keep getting NoSuchMethodError on LocationAwareLogger when running Jetty?
提问by Psycho Punch
I'm trying to embed Jetty server into my automated tests so I've added the following dependency in my project:
我正在尝试将 Jetty 服务器嵌入到我的自动化测试中,因此我在我的项目中添加了以下依赖项:
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlet</artifactId>
<version>7.6.13.v20130916</version>
<scope>test</scope>
</dependency>
I'm using Jetty 7 because the Web app uses Java 6, Servlet 2.5.
我使用 Jetty 7,因为 Web 应用程序使用 Java 6、Servlet 2.5。
However when I try to start embedded Jetty server, I get:
但是,当我尝试启动嵌入式 Jetty 服务器时,我得到:
java.lang.NoSuchMethodError: org.slf4j.spi.LocationAwareLogger.log(Lorg/slf4j/Marker;Ljava/lang/String;ILjava/lang/String;[Ljava/lang/Object;Ljava/lang/Throwable;)V
at org.eclipse.jetty.util.log.JettyAwareLogger.log(JettyAwareLogger.java:607)
at org.eclipse.jetty.util.log.JettyAwareLogger.warn(JettyAwareLogger.java:431)
at org.eclipse.jetty.util.log.Slf4jLog.warn(Slf4jLog.java:69)
at org.eclipse.jetty.util.component.AbstractLifeCycle.setFailed(AbstractLifeCycle.java:204)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:74)
I've been trying to figure out what's wrong but none of the steps I've taken so far addresses the issue. Here's a list of what I've done so far:
我一直试图找出问题所在,但到目前为止我采取的步骤都没有解决这个问题。以下是我迄今为止所做的工作列表:
- Trace transitive dependencies to search for incompatible versions of
slf4j-api
- Try out different versions of
slf4j-api
(1.5.11, 1.6.1, 1.6.4, 1.7.5) - Looked into the some sources of Jetty 7 particularly the pom.xml and found that there's a dependency to slf4j 1.6.1
- Looked into this similar questionand got
null
when trying to printorg.slf4j.spi.LocationAwareLogger
, andorg.slf4j.Marker
- 跟踪传递依赖以搜索不兼容的版本
slf4j-api
- 尝试不同版本的
slf4j-api
(1.5.11, 1.6.1, 1.6.4, 1.7.5) - 查看了 Jetty 7 的一些来源,特别是 pom.xml,发现对 slf4j 1.6.1 有依赖性
- 研究了这个类似的问题并
null
在尝试打印时得到了org.slf4j.spi.LocationAwareLogger
,并且org.slf4j.Marker
I hope someone can offer a fresh insight into this issue. Thanks.
我希望有人可以对这个问题提供新的见解。谢谢。
采纳答案by madhead
I bet you've faced a compatibility problembetween sl4j
jars. Try examinating mvn dependency:tree
output of your final artifact. Maybe you have two different versions of some sl4j
jar and you cannot predict which loads first. Try to equalize all sl4j
versions.
我敢打赌你遇到了jars之间的兼容性问题sl4j
。尝试检查mvn dependency:tree
最终工件的输出。也许您有一些sl4j
jar 的两个不同版本,并且您无法预测首先加载哪个版本。尝试均衡所有sl4j
版本。
OP: Please refer to the documentation on how I resolved this.
OP:请参阅有关我如何解决此问题的文档。
回答by Psycho Punch
The information on madhead's answerwas very helpful but I'm going to document the details of what I've done for the sake for others who (will) encounter the same problem.
关于madhead的回答的信息非常有帮助,但为了(将)遇到相同问题的其他人,我将记录我所做工作的详细信息。
As the answer mentioned suggested, it was a problem with slf4j
jars. To verify I did the following:
正如提到的答案所暗示的那样,这是slf4j
罐子的问题。为了验证我做了以下事情:
- Define exclusion on all dependencies that have dependencies on
slf4j
. - Follow option 2 from this suggestion.
- I wrote a unit test that just sysout's a String of my choosing, and define a breakpoint at that line.
- Then I debug the test as JUnit test, and open the Display view
- I needed to re-run it because
Display Result of Evaluating Selected Text
was disabled at first for some reason. - I found out that the runtime still refers to the 1.5.8 version of
slf4j
that was still being added into the classpath regardless if I specified exclusion for it.
- The project I'm working on depends on another project I'm also working on (it's a multi-Maven project project), which specified dependency to
slf4j-jdk14 1.5.8
, so I just updated it to1.6.1
.- I had to specify exclusion of
slf4j-api
underslf4j-jdk14 1.6.1
because it was referring to version 1.5.8, and add direct dependency toslf4j-api 1.6.1
.
- I had to specify exclusion of
- 对所有依赖于 的依赖定义排除
slf4j
。 - 遵循此建议中的选项 2 。
- 我写了一个单元测试,它只是 sysout 是我选择的一个字符串,并在该行定义了一个断点。
- 然后我将测试调试为 JUnit 测试,并打开显示视图
- 我需要重新运行它,因为
Display Result of Evaluating Selected Text
一开始由于某种原因被禁用了。 - 我发现运行时仍然指的是 1.5.8 版本,
slf4j
它仍然被添加到类路径中,无论我是否为它指定了排除。
- 我正在处理的项目依赖于我也在处理的另一个项目(它是一个多 Maven 项目项目),它指定了对 的依赖
slf4j-jdk14 1.5.8
,所以我只是将它更新为1.6.1
.- 我必须指定排除
slf4j-api
under,slf4j-jdk14 1.6.1
因为它指的是 1.5.8 版,并将直接依赖添加到slf4j-api 1.6.1
.
- 我必须指定排除