user3008626
user3008626

Reputation: 41

Exception in java project [java.lang.IllegalAccessError: tried to access field org.slf4j.impl.StaticLoggerBinder.SINGLETON]

Exception in thread "main" java.lang.IllegalAccessError: tried to access field org.slf4j.impl.StaticLoggerBinder.SINGLETON from class org.slf4j.LoggerFactory
    at org.slf4j.LoggerFactory.<clinit>(LoggerFactory.java:60)
    at org.hibernate.cfg.Configuration.<clinit>(Configuration.java:151)
    at com.erp.utility.Hibernatesession.getSession(Hibernatesession.java:24)
    at com.erp.dao.Country_Dao.getcountryByname(Country_Dao.java:88)
    at com.erp.service.Country_Service.getcountryByname(Country_Service.java:36)
    at com.erp.storedata.Store_Data.main(Store_Data.java:24)

Upvotes: 3

Views: 23747

Answers (4)

Beknazar
Beknazar

Reputation: 75

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

Upvotes: 0

SWAPNIL KUWAR
SWAPNIL KUWAR

Reputation: 422

remove the file slf4j-api.jar from your build path.

Upvotes: 0

LConrad
LConrad

Reputation: 846

Use a newer version of the slf4j-api.jar. There was a breaking change between version 1.5.5 and earlier and 1.5.6 and later. Use a version after 1.5.6, and that error should go away. For reference, see http://www.slf4j.org/faq.html#IllegalAccessError.

Upvotes: 5

Yubaraj
Yubaraj

Reputation: 3988

Please add following file on your project:

slf4j-log4j12.jar

Upvotes: 0

Related Questions