prismicio-community / java-kit

Community maintained development kit for Prismic and the Java language
https://prismic.io
15 stars 38 forks source link

[bug] SLF4J multiple bindings error when adding java-kit dependency in a new Spring Boot project #60

Closed damienbeaufils closed 7 years ago

damienbeaufils commented 7 years ago

Hello team!

If you create a new Spring Boot project (using start.spring.io for example) and add java-kit dependency, the application won't start because of a SLF4J binding error:

SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Detected both log4j-over-slf4j.jar AND bound slf4j-log4j12.jar on the class path, preempting StackOverflowError. 
SLF4J: See also http://www.slf4j.org/codes.html#log4jDelegationLoop for more details.
Exception in thread "main" java.lang.ExceptionInInitializerError
        at org.slf4j.impl.StaticLoggerBinder.<init>(StaticLoggerBinder.java:72)
        at org.slf4j.impl.StaticLoggerBinder.<clinit>(StaticLoggerBinder.java:45)
        at org.slf4j.LoggerFactory.bind(LoggerFactory.java:150)
        at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:124)
        at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:412)
        at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:357)
        at org.apache.commons.logging.LogFactory$Slf4jDelegate.createLocationAwareLog(LogFactory.java:174)
        at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:111)
        at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:99)
        at org.springframework.boot.SpringApplication.<clinit>(SpringApplication.java:198)
)
Caused by: java.lang.IllegalStateException: Detected both log4j-over-slf4j.jar AND bound slf4j-log4j12.jar on the class path, preempting StackOverflowError. See also http://www.slf4j.org/codes.html#log4jDelegationLoop for more details.
        at org.slf4j.impl.Log4jLoggerFactory.<clinit>(Log4jLoggerFactory.java:54)
        ... 11 more

It fails because java-kit has a dependency on slf4j-log4j12. The library should only use the SLF4J API without a specific binding (the project should choose the logger binding to use). More information on SLF4J and bindings here.

This PR fix this error by replacing slf4j-log4j12 and log4j dependencies by the simple slf4j-api dependency.

This PR depends on #56

Thanks and happy hacktoberfest!