首页 文章

我在使用JAX-WS时收到多个SLF4J绑定警告和错误启动处理程序和NoSuchMethodError

提问于
浏览
0

我正在 multiple SLF4J bindings warningsError starting handlersNoSuchMethodError: org.slf4j.spi.LocationAwareLogger.log(Lorg/slf4j/Marker;Ljava/lang/String;ILjava/lang/String;Ljava/lang/Throwable;)V

一切都很好,一旦我开始使用JAX-WS,所有这些业务都出现了 .

我的一位同事得到了同样的错误但是一旦他移除了jar(jcl-over-slf4j-1.5.8),现在对他来说没问题,

但我试过同样不适合我 .

我尝试在我的类路径1.slf4j-api-1.6.1.jar 2.slf4j-log4j12-1.6.1.jar和3.slf4j-simple-1.5.8.jar中逐个删除以下jar . 但是没有影响 .

当我在运行Jetty之前尝试maven clean时显示构建错误并且无法删除(xmlsec-1.4.4.jar),我手动删除了这个jar仍然没有构建任何东西到我的.M2存储库 .

这是控制台输出:

2011-12-23 08:44:55.765:INFO::jetty-6.1.26
    SLF4J: Class path contains multiple SLF4J bindings.
    SLF4J: Found binding in [jar:file:/C:/My_workspace/my_portal            /MyPortal/trunk/MyPortalWebApp/src/main/webapp/WEB-INF/lib/slf4j-        log4j12-1.6.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/C:/My_workspace/MyPortal/trunk/MyPortalWebApp/src/main/webapp/WEB-INF/lib/slf4j-simple-1.5.8.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
2011-12-23 08:44:57.140:INFO:/MyPortalWebApp:Initializing Spring root WebApplicationContext
2011-12-23 08:44:57.140:WARN::failed org.mortbay.jetty.webapp.WebAppContext@c4fe76    {/MyPortalWebApp,C:\My_workspace\MyPortal\trunk\MyPortalWebApp\src\main\webapp}: java.lang.NoSuchMethodError: org.slf4j.spi.LocationAwareLogger.log(Lorg/slf4j/Marker;Ljava/lang/String;ILjava/lang/String;Ljava/lang/Throwable;)V
2011-12-23 08:44:57.140:WARN::Error starting handlers
java.lang.NoSuchMethodError: org.slf4j.spi.LocationAwareLogger.log(Lorg/slf4j/Marker;Ljava/lang/String;ILjava/lang/String;Ljava/lang/Throwable;)V
at org.apache.commons.logging.impl.SLF4JLocationAwareLog.info(SLF4JLocationAwareLog.java:159)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:187)
at org.springframework.web.context.ContextLoaderListener.contextInitialized        (ContextLoaderListener.java:47)
at org.mortbay.jetty.handler.ContextHandler.startContext(ContextHandler.java:549)
at org.mortbay.jetty.servlet.Context.startContext(Context.java:136)
at org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1282)
at org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:518)
at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:499)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130)
at org.mortbay.jetty.Server.doStart(Server.java:224)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
at runjettyrun.Bootstrap.main(Bootstrap.java:82)

请给我一些输入我尝试了很多排列,但在运行Jetty时得到相同的(如上所述)输出 .

3 回答

  • 0

    Maven自动包含不同版本的slf4j-api和slf4j-log4j或slf4j-logging . 您可以通过输入以下内容找出包含它们的原因:

    mvn dependency:tree -Dincludes=org.slf4j
    

    由于您使用的是Jetty,因此Jetty可能会在您的应用程序中包含容器的类路径 . 尝试将以下行(如果它是Jetty 6或更早版本)添加到webapp的上下文文件中:

    <Set name="parentLoaderPriority">false</Set>
    

    它应该将容器jar和资源设置为低于webapp的优先级 .

  • 1

    根据错误消息,您的类路径(在 src/main/webapp/WEB-INF/lib/slf4j-simple-1.5.8.jar )仍然有 slf4j-simple-1.5.8.jar . 你在构建过程中使用了什么工具(Ant,Maven)?

  • 0

    这似乎是由加载的slf4j的不兼容版本引起的 . 试试这个

    -In eclipse, open the pom.xml file.
    -select the Dependency Hierarchy tab at the bottom. 
    -In the search filter, type the name "slf4j" and see all the dependencies that depend on slf4j for logging.
    

    如果多次找到,则可以通过在每个依赖项中写入它来排除它

    &ltexclusions>
          &ltexclusion>
            &ltartifactId>[artifactId]</artifactId>
            &ltgroupId>[groupId]</groupId>
          </exclusion>
        </exclusions>
    

相关问题