Exception in thread “main” java.lang.NoSuchMethodError: org.slf4j.impl.StaticLoggerBinder.getSingleton()Lorg/slf4j/impl/StaticLoggerBinder

醉酒当歌 提交于 2019-12-09 03:21:22

问题


My local environment: OSX 10.9.2, java1.6

I use java api to connect hbase and maven to manage my project, I added Hbase-0.94.17 and Hadoop-core-1.0.4 into pom.xml, when I ran my .java program to connect Hbase I got the following error:

SLF4J: slf4j-api 1.6.x (or later) is incompatible with this binding.
SLF4J: Your binding is version 1.5.5 or earlier.
SLF4J: Upgrade your binding to version 1.6.x.
Exception in thread "main" java.lang.NoSuchMethodError: org.slf4j.impl.StaticLoggerBinder.getSingleton()Lorg/slf4j/impl/StaticLoggerBinder;
    at org.slf4j.LoggerFactory.bind(LoggerFactory.java:128)
    at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:107)
    at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:295)
    at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:269)
    at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:281)
    at org.apache.zookeeper.ZooKeeper.<clinit>(ZooKeeper.java:94)
    at org.apache.hadoop.hbase.zookeeper.RecoverableZooKeeper.<init>(RecoverableZooKeeper.java:98)
    at org.apache.hadoop.hbase.zookeeper.ZKUtil.connect(ZKUtil.java:127)
    at org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher.<init>(ZooKeeperWatcher.java:153)
    at org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher.<init>(ZooKeeperWatcher.java:127)
    at org.apache.hadoop.hbase.client.HConnectionManager$HConnectionImplementation.getZooKeeperWatcher(HConnectionManager.java:1505)
    at org.apache.hadoop.hbase.client.HConnectionManager$HConnectionImplementation.ensureZookeeperTrackers(HConnectionManager.java:713)
    at org.apache.hadoop.hbase.client.HConnectionManager$HConnectionImplementation.locateRegion(HConnectionManager.java:983)
    at org.apache.hadoop.hbase.client.HConnectionManager$HConnectionImplementation.locateRegion(HConnectionManager.java:958)
    at org.apache.hadoop.hbase.client.HTable.finishSetup(HTable.java:251)
    at org.apache.hadoop.hbase.client.HTable.<init>(HTable.java:155)
    at org.apache.hadoop.hbase.client.HTable.<init>(HTable.java:129)
    at org.geogit.storage.hbase.MyLittleHBaseClient.main(MyLittleHBaseClient.java:29)

Here is what I got after ran mvm dependency:tree

INFO] --- maven-dependency-plugin:2.2:tree (default-cli) @ geogit-hbase ---
[INFO] org.geogit:geogit-hbase:jar:0.8-SNAPSHOT
[INFO] +- org.geogit:geogit-core:jar:0.8-SNAPSHOT:compile
[INFO] |  +- org.slf4j:slf4j-api:jar:1.7.5:compile
[INFO] |  +- com.vividsolutions:jts:jar:1.13:compile
[INFO] |  +- org.geotools:gt-opengis:jar:10.5:compile
[INFO] |  |  +- net.java.dev.jsr-275:jsr-275:jar:1.0-beta-2:compile
[INFO] |  |  +- java3d:vecmath:jar:1.3.2:compile
[INFO] |  |  +- commons-pool:commons-pool:jar:1.5.4:compile
[INFO] |  |  \- javax.media:jai_core:jar:1.1.3:compile
[INFO] |  +- org.geotools:gt-referencing:jar:10.5:compile
[INFO] |  |  +- org.geotools:gt-metadata:jar:10.5:compile
[INFO] |  |  \- jgridshift:jgridshift:jar:1.0:compile
[INFO] |  +- org.geotools:gt-epsg-hsql:jar:10.5:compile
[INFO] |  |  \- hsqldb:hsqldb:jar:1.8.0.7:compile
[INFO] |  +- org.geotools:gt-main:jar:10.5:compile
[INFO] |  |  \- org.geotools:gt-api:jar:10.5:compile
[INFO] |  +- org.geotools:gt-cql:jar:10.5:compile
[INFO] |  +- net.sourceforge.findbugs:jsr305:jar:1.3.7:compile
[INFO] |  +- com.google.inject:guice:jar:3.0:compile
[INFO] |  |  +- javax.inject:javax.inject:jar:1:compile
[INFO] |  |  \- aopalliance:aopalliance:jar:1.0:compile
[INFO] |  +- com.google.inject.extensions:guice-multibindings:jar:3.0:compile
[INFO] |  +- com.google.code.gson:gson:jar:2.2.2:compile
[INFO] |  \- com.ning:compress-lzf:jar:0.9.8:compile
[INFO] +- org.apache.hbase:hbase-client:jar:0.98.0-hadoop2:compile
[INFO] |  +- org.apache.hbase:hbase-common:jar:0.98.0-hadoop2:compile
[INFO] |  |  +- commons-collections:commons-collections:jar:3.2.1:compile
[INFO] |  |  \- log4j:log4j:jar:1.2.17:compile
[INFO] |  +- org.apache.hbase:hbase-protocol:jar:0.98.0-hadoop2:compile
[INFO] |  +- commons-codec:commons-codec:jar:1.7:compile
[INFO] |  +- commons-io:commons-io:jar:2.4:compile
[INFO] |  +- commons-lang:commons-lang:jar:2.6:compile
[INFO] |  +- commons-logging:commons-logging:jar:1.1.1:compile
[INFO] |  +- com.google.protobuf:protobuf-java:jar:2.5.0:compile
[INFO] |  +- io.netty:netty:jar:3.6.6.Final:compile
[INFO] |  +- org.apache.zookeeper:zookeeper:jar:3.4.5:compile
[INFO] |  |  \- org.slf4j:slf4j-log4j12:jar:1.6.1:compile
[INFO] |  +- org.cloudera.htrace:htrace-core:jar:2.04:compile
[INFO] |  |  \- org.mortbay.jetty:jetty-util:jar:6.1.26:compile
[INFO] |  +- org.codehaus.jackson:jackson-mapper-asl:jar:1.8.8:compile
[INFO] |  |  \- org.codehaus.jackson:jackson-core-asl:jar:1.8.8:compile
[INFO] |  +- org.apache.hadoop:hadoop-common:jar:2.2.0:compile
[INFO] |  |  +- commons-cli:commons-cli:jar:1.2:compile
[INFO] |  |  +- org.apache.commons:commons-math:jar:2.1:compile
[INFO] |  |  +- xmlenc:xmlenc:jar:0.52:compile
[INFO] |  |  +- commons-httpclient:commons-httpclient:jar:3.1:compile
[INFO] |  |  +- commons-net:commons-net:jar:3.1:compile
[INFO] |  |  +- org.mortbay.jetty:jetty:jar:6.1.26:compile
[INFO] |  |  +- com.sun.jersey:jersey-core:jar:1.9:compile
[INFO] |  |  +- com.sun.jersey:jersey-json:jar:1.9:compile
[INFO] |  |  |  +- org.codehaus.jettison:jettison:jar:1.0.1:compile (version managed from 1.1)
[INFO] |  |  |  |  \- stax:stax-api:jar:1.0.1:compile
[INFO] |  |  |  +- com.sun.xml.bind:jaxb-impl:jar:2.2.3-1:compile
[INFO] |  |  |  |  \- javax.xml.bind:jaxb-api:jar:2.2.2:compile
[INFO] |  |  |  |     \- javax.activation:activation:jar:1.1:compile
[INFO] |  |  |  +- org.codehaus.jackson:jackson-jaxrs:jar:1.8.3:compile
[INFO] |  |  |  \- org.codehaus.jackson:jackson-xc:jar:1.8.3:compile
[INFO] |  |  +- commons-el:commons-el:jar:1.0:runtime
[INFO] |  |  +- net.java.dev.jets3t:jets3t:jar:0.6.1:compile
[INFO] |  |  +- commons-configuration:commons-configuration:jar:1.6:compile
[INFO] |  |  |  +- commons-digester:commons-digester:jar:1.8:compile
[INFO] |  |  |  |  \- commons-beanutils:commons-beanutils:jar:1.7.0:compile
[INFO] |  |  |  \- commons-beanutils:commons-beanutils-core:jar:1.8.0:compile
[INFO] |  |  +- org.apache.avro:avro:jar:1.7.4:compile
[INFO] |  |  |  +- com.thoughtworks.paranamer:paranamer:jar:2.3:compile
[INFO] |  |  |  \- org.xerial.snappy:snappy-java:jar:1.0.4.1:compile
[INFO] |  |  +- com.jcraft:jsch:jar:0.1.42:compile
[INFO] |  |  \- org.apache.commons:commons-compress:jar:1.4.1:compile
[INFO] |  |     \- org.tukaani:xz:jar:1.0:compile
[INFO] |  +- org.apache.hadoop:hadoop-auth:jar:2.2.0:compile
[INFO] |  +- org.apache.hadoop:hadoop-mapreduce-client-core:jar:2.2.0:compile
[INFO] |  |  +- org.apache.hadoop:hadoop-yarn-common:jar:2.2.0:compile
[INFO] |  |  |  +- org.apache.hadoop:hadoop-yarn-api:jar:2.2.0:compile
[INFO] |  |  |  +- com.sun.jersey:jersey-server:jar:1.9:compile
[INFO] |  |  |  |  \- asm:asm:jar:3.1:compile
[INFO] |  |  |  \- com.sun.jersey.contribs:jersey-guice:jar:1.9:compile
[INFO] |  |  \- com.google.inject.extensions:guice-servlet:jar:3.0:compile
[INFO] |  +- org.apache.hadoop:hadoop-annotations:jar:2.2.0:compile
[INFO] |  \- com.github.stephenc.findbugs:findbugs-annotations:jar:1.3.9-1:compile
[INFO] +- org.geogit:geogit-mongodb:jar:0.8-SNAPSHOT:compile
[INFO] |  +- org.geogit:geogit-blueprints:jar:0.8-SNAPSHOT:compile
[INFO] |  |  +- com.tinkerpop.blueprints:blueprints-core:jar:2.4.0:compile
[INFO] |  |  |  +- com.fasterxml.jackson.datatype:jackson-datatype-json-org:jar:2.1.2:compile
[INFO] |  |  |  |  +- com.fasterxml.jackson.core:jackson-core:jar:2.1.2:compile
[INFO] |  |  |  |  +- com.fasterxml.jackson.core:jackson-databind:jar:2.1.2:compile
[INFO] |  |  |  |  |  \- com.fasterxml.jackson.core:jackson-annotations:jar:2.1.1:compile
[INFO] |  |  |  |  \- org.json:json:jar:20090211:compile
[INFO] |  |  |  \- colt:colt:jar:1.2.0:compile
[INFO] |  |  |     \- concurrent:concurrent:jar:1.3.4:compile
[INFO] |  |  \- com.tinkerpop.gremlin:gremlin-java:jar:2.4.0:compile
[INFO] |  |     \- com.tinkerpop:pipes:jar:2.4.0:compile
[INFO] |  \- org.mongodb:mongo-java-driver:jar:2.11.3:compile
[INFO] +- com.google.guava:guava:jar:14.0.1:compile
[INFO] +- org.geogit:geogit-core:jar:tests:0.8-SNAPSHOT:test
[INFO] \- junit:junit:jar:4.10:test
[INFO]    \- org.hamcrest:hamcrest-core:jar:1.1:test

And here I attach my pom.xml

<?xml version="1.0" encoding="ISO-8859-1"?>
<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/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <parent>
    <groupId>org.geogit</groupId>
    <artifactId>storage</artifactId>
    <version>0.8-SNAPSHOT</version>
  </parent>

  <groupId>org.geogit</groupId>
  <artifactId>geogit-hbase</artifactId>
  <packaging>jar</packaging>
  <name>HBase Storage for GeoGit objects</name>

  <dependencies>
    <dependency>
      <groupId>org.geogit</groupId>
      <artifactId>geogit-core</artifactId>
      <version>${project.version}</version>
    </dependency>

    <dependency>
        <groupId>org.apache.hbase</groupId>
        <artifactId>hbase</artifactId>
        <version>0.94.17</version>
    </dependency>

    <dependency>
        <groupId>org.apache.hadoop</groupId>
        <artifactId>hadoop-core</artifactId>
        <version>1.0.4</version>
    </dependency>

    <!-- is this necessary? -->
    <!--
    <dependency>
      <groupId>com.boundlessgeo</groupId>
      <artifactId>blongo</artifactId>
      <version>0.1</version>
    </dependency>
    -->
    <!-- is this necessary? -->
    <dependency>
      <groupId>com.google.guava</groupId>
      <artifactId>guava</artifactId>
    </dependency>

    <!-- Test scope dependencies -->
    <dependency>
      <groupId>org.geogit</groupId>
      <artifactId>geogit-core</artifactId>
      <version>${project.version}</version>
      <scope>test</scope>
      <classifier>tests</classifier>
    </dependency>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <scope>test</scope>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <configuration>
          <skip>true</skip>
        </configuration>
      </plugin>
    </plugins>
  </build>

  <profiles>
  </profiles>
</project>

回答1:


Have slf4j-api and choose a SLF4J binding of corresponding version, and add them as dependencies in your own POM. It is quite possibly some of your dependencies transitively resolve an incompatible version of SLF4J binding which caused the problem. Find which library is bringing in the unwanted SLF4J binding (you can easily do so by mvn dependency:tree), and add corresponding exclusion in your dependency to that lib.

(Normally SLF4J binding shouldn't be declared in library. It is in fact something wrong that you may want to report to the library developer once you found the actual cause)


Update

That's exactly what I am talking about:

From your dependency tree:

[INFO] +- org.geogit:geogit-core:jar:0.8-SNAPSHOT:compile
[INFO] |  +- org.slf4j:slf4j-api:jar:1.7.5:compile

.....

[INFO] +- org.apache.hbase:hbase-client:jar:0.98.0-hadoop2:compile
       .....
[INFO] |  +- org.apache.zookeeper:zookeeper:jar:3.4.5:compile
[INFO] |  |  \- org.slf4j:slf4j-log4j12:jar:1.6.1:compile

You got slf4j-log4j12 binding from hbase-client, and that's version 1.6.1

However, slf4j-api you have in your project is version 1.7.5. They are not compatible.

Proper way to solve is:

  1. Exclude slf4j-log4j12 from your dependency of hbase-client
  2. Declare a compatible SLF4J binding in your own project

You should also report this as a bug to zookeeper/hbase developer as it is not appropriate for a library to include SLF4J binding as compile scope dependency.



来源:https://stackoverflow.com/questions/22800894/exception-in-thread-main-java-lang-nosuchmethoderror-org-slf4j-impl-staticlog

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!