Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.lang.IllegalAccessError: tried to access field org.slf4j.impl.StaticLoggerBinder.SINGLETON from class org.slf4j.LoggerFactory

Tags:

java

gwt

I am facing this error while running my GWT application.

I have these jar files in my classpath: slf4j-api & slf4j-log4j12

Any idea what could be the reason?

like image 830
junaidp Avatar asked Jan 27 '12 08:01

junaidp


2 Answers

This problem is due to a change in slf4j-log4j12 jar. From version 1.5.6 it doesn't allow to access the field org.slf4j.impl.StaticLoggerBinder.SINGLETON.

To resolve it, use the newest jars (or at least version 1.5.6 onward) for both slf4j-api & slf4j-log4j12.

<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-api</artifactId>
    <version>1.5.6</version>
</dependency>

<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-log4j12</artifactId>
    <version>1.5.6</version>
</dependency>
like image 83
bnguyen82 Avatar answered Nov 15 '22 11:11

bnguyen82


Finally resolved this problem in my SpringBoot application. If updating version is not helping this might help. Sometimes other libraries might bring different versions of this dependencies. These are the steps:

  1. By error stack trace figure out which dependency is giving this issue
  2. Get maven dependency plugin tree. Using this tree details find out if this library is coming as part of the some other dependency. In my case, the logback-classic and log4j-over-slf4j were giving this problem. They came together under spring-boot-starter-web
  3. Use <exclusions><exclusion></exclusion></exclusions> in your pom.xml in that dependency for the libraries that giving this issue. In my case it looks like this:
         <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <exclusions>
                <exclusion>
                    <artifactId>logback-classic</artifactId>
                    <groupId>ch.qos.logback</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>log4j-over-slf4j</artifactId>
                    <groupId>org.slf4j</groupId>
                </exclusion>
            </exclusions>
        </dependency>

References:
http://www.slf4j.org/faq.html#IllegalAccessError
http://www.slf4j.org/codes.html#multiple_bindings

like image 41
Beknazar Avatar answered Nov 15 '22 12:11

Beknazar