1

我正在尝试将 Solr 与 slfj4 和 logback 一起使用,当我使用 CTRL+C 关闭 Solr 时,出现此错误:

 java.lang.NoSuchMethodError: org.slf4j.spi.LocationAwareLogger.log(Lorg/slf4j/Marker;Ljava/lang/String;ILjava/lang/String;[Ljava/lang/Object;Ljava/lang/Throwable;)V

这不会在编译时发生。

我在 1.6.4 版本中检查了 org.slf4j.spi.LocationAwareLogger.log 的方法签名,它似乎是正确的:

  public void log(Marker marker, String fqcn, int level, String message, Object[] argArray, Throwable t);

完整的堆栈跟踪:

2012-04-27 12:02:09.806 [Shutdown] ERROR o.a.s.h.c.HttpShardHandlerFactory - 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.apache.commons.logging.impl.SLF4JLocationAwareLog.debug(SLF4JLocationAwareLog.java:133
)
        at org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager.shutdown(ThreadSafeClientConnManager.java:282)
        at org.apache.solr.handler.component.HttpShardHandlerFactory.close(HttpShardHandlerFactory.java:172)
        at org.apache.solr.core.CoreContainer.shutdown(CoreContainer.java:599)
        at org.apache.solr.servlet.SolrDispatchFilter.destroy(SolrDispatchFilter.java:124)
        at org.mortbay.jetty.servlet.FilterHolder.destroyInstance(FilterHolder.java:127)
        at org.mortbay.jetty.servlet.FilterHolder.doStop(FilterHolder.java:107)
        at org.mortbay.component.AbstractLifeCycle.stop(AbstractLifeCycle.java:76)
        at org.mortbay.jetty.servlet.ServletHandler.doStop(ServletHandler.java:176)        at org.mortbay.component.AbstractLifeCycle.stop(AbstractLifeCycle.java:76)
        at org.mortbay.jetty.handler.HandlerWrapper.doStop(HandlerWrapper.java:142)
        at org.mortbay.component.AbstractLifeCycle.stop(AbstractLifeCycle.java:76)
        at org.mortbay.jetty.handler.HandlerWrapper.doStop(HandlerWrapper.java:142)        at org.mortbay.jetty.servlet.SessionHandler.doStop(SessionHandler.java:125)
        at org.mortbay.component.AbstractLifeCycle.stop(AbstractLifeCycle.java:76)
        at org.mortbay.jetty.handler.HandlerWrapper.doStop(HandlerWrapper.java:142)
        at org.mortbay.jetty.handler.ContextHandler.doStop(ContextHandler.java:592)        at org.mortbay.jetty.webapp.WebAppContext.doStop(WebAppContext.java:537)
        at org.mortbay.jetty.plugin.Jetty6PluginWebAppContext.doStop(Jetty6PluginWebAppContext.java:1
23)
        at org.mortbay.component.AbstractLifeCycle.stop(AbstractLifeCycle.java:76)        at org.mortbay.jetty.handler.HandlerCollection.doStop(HandlerCollection.java:169)
        at org.mortbay.component.AbstractLifeCycle.stop(AbstractLifeCycle.java:76)
        at org.mortbay.jetty.handler.HandlerCollection.doStop(HandlerCollection.java:169)
        at org.mortbay.component.AbstractLifeCycle.stop(AbstractLifeCycle.java:76)        at org.mortbay.jetty.handler.HandlerWrapper.doStop(HandlerWrapper.java:142)
        at org.mortbay.jetty.Server.doStop(Server.java:283)
        at org.mortbay.component.AbstractLifeCycle.stop(AbstractLifeCycle.java:76)
        at org.mortbay.jetty.Server$ShutdownHookThread.run(Server.java:561)

我的pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

    <modelVersion>4.0.0</modelVersion>
    <groupId>com.shutterstock</groupId>
    <artifactId>solr</artifactId>
    <version>0.0.1</version>
    <packaging>war</packaging>
    <name>Apache Solr Web Application</name>
    <properties>
        <solr.build.dir>../build/solr-maven</solr.build.dir>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <repositories>
        <repository>
            <id>central</id>
            <name>Maven Repository Switchboard</name>
            <layout>default</layout>
            <url>http://repo1.maven.org/maven2</url>
        </repository>
        <repository>
            <id>trunk</id>
            <name>solr snapshots</name>
            <url>http://repository.apache.org/snapshots</url>
        </repository>
        <repository>
            <id>ubercraft</id>
            <name>ubercraft statsd packages</name>
            <url>https://oss.sonatype.org/content/repositories/releases</url>
        </repository>
    </repositories>

    <pluginRepositories>
        <pluginRepository>
            <id>central</id>
            <name>Maven Plugin Repository</name>
            <url>http://repo1.maven.org/maven2</url>
            <layout>default</layout>
        </pluginRepository>
    </pluginRepositories>

    <dependencies>
        <dependency>
            <groupId>org.apache.solr</groupId>
            <artifactId>solr</artifactId>
            <version>4.0-SNAPSHOT</version>
            <type>war</type>
        </dependency>
        <dependency>
            <groupId>org.apache.solr</groupId>
            <artifactId>solr-core</artifactId>
            <version>4.0-SNAPSHOT</version>
            <exclusions>
                <exclusion>
                    <artifactId>slf4j-api</artifactId>
                    <groupId>org.slf4j</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>jcl-over-slf4j</artifactId>
                    <groupId>org.slf4j</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>slf4j-jdk14</artifactId>
                    <groupId>org.slf4j</groupId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.apache.solr</groupId>
            <artifactId>solr-analysis-extras</artifactId>
            <version>4.0-SNAPSHOT</version>
            <exclusions>
                <exclusion>
                    <artifactId>slf4j-api</artifactId>
                    <groupId>org.slf4j</groupId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.apache.solr</groupId>
            <artifactId>solr-commons-csv</artifactId>
            <version>4.0-SNAPSHOT</version>
            <exclusions>
                <exclusion>
                    <artifactId>slf4j-api</artifactId>
                    <groupId>org.slf4j</groupId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.apache.lucene</groupId>
            <artifactId>lucene-core</artifactId>
            <version>4.0-SNAPSHOT</version>
            <type>jar</type>
        </dependency>
        <dependency>
            <groupId>org.apache.lucene</groupId>
            <artifactId>lucene-spatial</artifactId>
            <version>4.0-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>org.apache.lucene</groupId>
            <artifactId>lucene-queryparser</artifactId>
            <version>4.0-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>org.apache.lucene</groupId>
            <artifactId>lucene-analyzers-common</artifactId>
            <version>4.0-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>org.apache.lucene</groupId>
            <artifactId>lucene-queries</artifactId>
            <version>4.0-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.6.4</version>
        </dependency>
        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
            <version>0.9.22</version>
        </dependency>
        <dependency>
            <groupId>org.ubercraft.statsd</groupId>
            <artifactId>statsd-over-slf4j</artifactId>
            <version>1.0.0</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.mortbay.jetty</groupId>
                <artifactId>maven-jetty-plugin</artifactId>
                <version>6.1.26</version>
            </plugin>
        </plugins>
    </build>

</project>

Maven依赖树:

$ mvn dependency:tree
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building Apache Solr Web Application 0.0.1
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-dependency-plugin:2.1:tree (default-cli) @ solr ---
[INFO] com.shutterstock:solr:war:0.0.1
[INFO] +- org.apache.solr:solr:war:4.0-SNAPSHOT:compile
[INFO] +- org.apache.solr:solr-core:jar:4.0-SNAPSHOT:compile
[INFO] |  +- org.apache.solr:solr-solrj:jar:4.0-SNAPSHOT:compile
[INFO] |  |  \- org.apache.zookeeper:zookeeper:jar:3.3.4:compile
[INFO] |  +- org.apache.lucene:lucene-analyzers-kuromoji:jar:4.0-SNAPSHOT:compile
[INFO] |  +- org.apache.lucene:lucene-analyzers-morfologik:jar:4.0-SNAPSHOT:compile
[INFO] |  |  \- org.carrot2:morfologik-polish:jar:1.5.2:compile
[INFO] |  |     \- org.carrot2:morfologik-stemming:jar:1.5.2:compile
[INFO] |  |        \- org.carrot2:morfologik-fsa:jar:1.5.2:compile
[INFO] |  +- org.apache.lucene:lucene-analyzers-phonetic:jar:4.0-SNAPSHOT:compile
[INFO] |  +- org.apache.lucene:lucene-highlighter:jar:4.0-SNAPSHOT:compile
[INFO] |  +- org.apache.lucene:lucene-memory:jar:4.0-SNAPSHOT:compile
[INFO] |  +- org.apache.lucene:lucene-misc:jar:4.0-SNAPSHOT:compile
[INFO] |  +- org.apache.lucene:lucene-suggest:jar:4.0-SNAPSHOT:compile
[INFO] |  +- org.apache.lucene:lucene-grouping:jar:4.0-SNAPSHOT:compile
[INFO] |  +- commons-codec:commons-codec:jar:1.6:compile
[INFO] |  +- commons-fileupload:commons-fileupload:jar:1.2.1:compile
[INFO] |  +- org.apache.httpcomponents:httpmime:jar:4.1.3:compile
[INFO] |  |  +- org.apache.httpcomponents:httpcore:jar:4.1.4:compile
[INFO] |  |  \- commons-logging:commons-logging:jar:1.1.1:compile
[INFO] |  +- commons-io:commons-io:jar:2.1:compile
[INFO] |  +- commons-lang:commons-lang:jar:2.6:compile
[INFO] |  +- com.google.guava:guava:jar:r05:compile
[INFO] |  +- org.codehaus.woodstox:wstx-asl:jar:3.2.7:runtime
[INFO] |  \- org.apache.httpcomponents:httpclient:jar:4.1.3:compile
[INFO] +- org.apache.solr:solr-analysis-extras:jar:4.0-SNAPSHOT:compile
[INFO] |  +- org.apache.lucene:lucene-analyzers-icu:jar:4.0-SNAPSHOT:compile
[INFO] |  |  \- com.ibm.icu:icu4j:jar:4.8.1.1:compile
[INFO] |  +- org.apache.lucene:lucene-analyzers-smartcn:jar:4.0-SNAPSHOT:compile
[INFO] |  \- org.apache.lucene:lucene-analyzers-stempel:jar:4.0-SNAPSHOT:compile
[INFO] +- org.apache.solr:solr-commons-csv:jar:4.0-SNAPSHOT:compile
[INFO] +- org.apache.lucene:lucene-core:jar:4.0-SNAPSHOT:compile
[INFO] +- org.apache.lucene:lucene-spatial:jar:4.0-SNAPSHOT:compile
[INFO] |  \- com.spatial4j:spatial4j:jar:0.2:compile
[INFO] +- org.apache.lucene:lucene-queryparser:jar:4.0-SNAPSHOT:compile
[INFO] |  \- org.apache.lucene:lucene-sandbox:jar:4.0-SNAPSHOT:compile
[INFO] |     \- jakarta-regexp:jakarta-regexp:jar:1.4:compile
[INFO] +- org.apache.lucene:lucene-analyzers-common:jar:4.0-SNAPSHOT:compile
[INFO] +- org.apache.lucene:lucene-queries:jar:4.0-SNAPSHOT:compile
[INFO] +- org.slf4j:slf4j-api:jar:1.6.4:compile
[INFO] +- ch.qos.logback:logback-classic:jar:0.9.22:compile
[INFO] |  \- ch.qos.logback:logback-core:jar:0.9.22:compile
[INFO] \- org.ubercraft.statsd:statsd-over-slf4j:jar:1.0.0:compile
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.383s
[INFO] Finished at: Fri Apr 27 12:14:43 EDT 2012
[INFO] Final Memory: 10M/482M
[INFO] ------------------------------------------------------------------------
4

1 回答 1

5

确保您使用的是 sfl4j 的正确版本

从例外:

    2012-04-27 12:02:09.806 [Shutdown] ERROR o.a.s.h.c.HttpShardHandlerFactory - 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.apache.commons.logging.impl.SLF4JLocationAwareLog.debug(SLF4JLocationAwareLog.java:133
)
        at org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager.shutdown(ThreadSafeClientConnManager.java:282)
        a

表明错误来自 Apache HTTP 的库,来自您的 maven 依赖树,它包含:

org.apache.httpcomponents:httpclient:jar:4.1.3

根据他们的文档here,在您使用 1.6.4 时使用 slf4j 版本 1.5.11

于 2012-04-27T17:07:34.153 回答