Adding slf4j-simple.jar doesn't solve: Failed to load class "org.slf4j.impl.StaticLoggerBinder" - spring-boot

On starting spring boot application, I get:
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
In maven dependency tree, I see following occurrences of slf4j:
org.slf4j:slf4j-api:jar:1.7.30:compile
com.typesafe.akka:akka-slf4j_2.11:jar:2.5.21:compile
org.clapper:grizzled-slf4j_2.11:jar:1.3.2:compile
org.apache.logging.log4j:log4j-to-slf4j:jar:2.13.3:compile
org.slf4j:jul-to-slf4j:jar:1.7.30:compile
At this link, it mentions to add slf4j-simple.jar to solve it. I did so:
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>2.0.0-alpha1</version>
</dependency>
....but I still get the error.
How to solve it?

Related

Gradle with Apache Jena 3.11.0

I am trying to create a shadowjar including the latest Apache Jena 3.11 using the gradle build system and additional java code to create an "uber" package. To do so I found information here: https://jena.apache.org/documentation/notes/jena-repack.html however I am having difficulty to translate this to a gradle setup.
Does anyone knows how to achieve this?
5 actionable tasks: 1 executed, 4 up-to-date
Creating memory store
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Exception in thread "main" java.lang.ExceptionInInitializerError
at nl.wur.ssb.RDFSimpleCon.RDFSimpleCon.createEmptyStore(RDFSimpleCon.java:150)
at nl.wur.ssb.RDFSimpleCon.RDFSimpleCon.<init>(RDFSimpleCon.java:62)
at nl.wur.ssb.RDFSimpleCon.RDFSimpleCon.<init>(RDFSimpleCon.java:159)
at nl.wur.ssb.RDFSimpleCon.Test.main(Test.java:7)
Caused by: java.lang.NullPointerException
at org.apache.jena.tdb.sys.EnvTDB.processGlobalSystemProperties(EnvTDB.java:33)
at org.apache.jena.tdb.TDB.init(TDB.java:252)
at org.apache.jena.tdb.sys.InitTDB.start(InitTDB.java:29)
at org.apache.jena.sys.JenaSystem.lambda$init$2(JenaSystem.java:116)
at java.util.ArrayList.forEach(ArrayList.java:1257)
at org.apache.jena.sys.JenaSystem.forEach(JenaSystem.java:191)
at org.apache.jena.sys.JenaSystem.forEach(JenaSystem.java:168)
at org.apache.jena.sys.JenaSystem.init(JenaSystem.java:114)
at org.apache.jena.tdb.TDBFactory.<clinit>(TDBFactory.java:40)
... 4 more
Java ServiceLoader files need to be merged when creating a repackaged jar file.
For Gradle, this is done with "mergeServiceFiles()" when using the shadowJar.
https://jena.apache.org/documentation/notes/jena-repack.html has the instructions for the Maven shade plugin.

Adding javax.servlet-api dependency throws exception that org.slf4j.impl.StaticLoggerBinder faild to load but i don't use sl4j, i use thymeleaf

Basicaly title. I'm trying to run simple spring5 + thymeleaf project. If i don't add servlet-api i get an error that
cannot access javax.servlet.ServletException
But if i add servlet-api, project starts and works fine , but i get an error on startup:
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
But i don't use sl4j, i use thymeleaf. How does servlet exception connected with sl4j and how should i manage it?
UPD
I understand that my question is wrong. But i need help with connected problem:
As someone suggested i added
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.5</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</dependency>
But i still get Failed to load class "org.slf4j.impl.StaticLoggerBinder". exception. Any ideas?
UPD
as someone mentioned here this is a bug of ide
Add slf4j.jar in your dependency or your project. Spring internally use slf4j for its own logging.
I'm using IntelIj idea.
As someone sugested i added log4j and sl4j dependencies becouse servlet-api uses loging by default. And my exception that class is failed to load is just a bug of ide as it was mentioned in another question and everything including logging works fine.

Setting Logger Implementation to Test Scope with Maven for IntelliJ

For automated tests of an API, I need to have an implementation of a logger present. But the logger is supposed to not ship with the API itself. To that end I set up the relevant part of the pom.xml of the API module itself like so:
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.25</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.3</version>
<scope>test</scope>
</dependency>
When I manually run maven from the command line the test where the logger is relevant passes. But when I run the test file from within Intellij I get the following error:
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
I have spent several hours now trying to figure out what is wrong and followed multiple tutorials. None actually covered the sort of setup I need though and so I am still stuck with this error.
Do you know what the actual problem is here and how to set this up correctly?

PropertiesLauncher working differently with slf4j bindings in newer version of spring boot

I have a spring boot project that uses the PropertiesLauncher to load a bunch of hadoop and hive jars at startup to provide connectivity to hadoop and hive. I am using slf4j with logback in my project and when I load the hive-jdbc jars they bring along log4j classes which cause a conflict. This is not an issue as long as I am using springBootVersion = '1.2.3.RELEASE' in my build.gradle.
I have configured the PropertiesLauncher in my build.gradle file
springBoot { layout = 'ZIP' }
bootRepackage {
mainClass = 'com....Application'
enabled = true
}
And starting up the application using this command
java -Dloader.path=file:///etc/hadoop/conf,file:///etc/hive/conf,jars,
byod-ui-1.0.0.SNAPSHOT.jar -jar byod-ui-1.0.0.SNAPSHOT.jar
When the projects start up, the output looks like this
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/home/byod/byod-ui-1.0.0.SNAPSHOT.jar!/lib/logback-classic-1.1.3.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/home/byod/jars/hive-jdbc-0.14.0.2.2.8.0-3150-standalone.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/home/byod/jars/hive-jdbc.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [ch.qos.logback.classic.util.ContextSelectorStaticBinder]
Notice that my application jar is detected first and then the hive-jdbc jars and I am assuming because my jar is detected first, the final line indicates that the binding selected is ch.qos.logback.classic.util.ContextSelectorStaticBinder which is logback so everything works great.
If I only change the spring boot version (and nothing else in code or configuration or jars/classpath setup) to springBootVersion = '1.3.2.RELEASE' Now the output looks like this
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/home/byod/jars/hive-jdbc.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/home/byod/jars/hive-jdbc-0.14.0.2.2.8.0-3150-standalone.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/home/byod/byod-ui-1.0.0.SNAPSHOT.jar!/lib/logback-classic-1.1.3.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:53)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.IllegalArgumentException: LoggerFactory is not a Logback LoggerContext
but Logback is on the classpath. Either remove Logback or the competing implementation
(class org.slf4j.impl.Log4jLoggerFactory loaded from jar:file:/home/aq728y/byod/jars/hive-jdbc.jar!/).
If you are using WebLogic you will need to add 'org.slf4j' to prefer-application-packages in WEB-INF/weblogic.xml Object
of class [org.slf4j.impl.Log4jLoggerFactory] must be an instance of class ch.qos.logback.classic.LoggerContext
Now the order of detected bindings is different. This time, first bindings are detected from the hive-jdbc.jar instead of my application jar and that leads to log4j becoming the "actual binding" at the end. This results in an error and the application start up FAILS.
I wanted to provide these details and post this question to see if there were some changes in the recent version of spring boot that would explain this behavior and possibly help with the resolution. If possible, I would like to continue to use logback and not have to switch to log4j.
In Spring Boot 1.3.x the handling of classpath order has changed.
In 1.2.x, the order was reversed, so specifying
-Dloader.path=file:///etc/hadoop/conf,file:///etc/hive/conf,jars,
byod-ui-1.0.0.SNAPSHOT.jar
produced the following classpath order:
byod-ui-1.0.0.SNAPSHOT.jar
jars
file:///etc/hive/conf
file:///etc/hadoop/conf
In 1.3.x the classpath isn't reverted anymore, so the same commandline options leads to the follwing classpath order:
file:///etc/hadoop/conf
file:///etc/hive/conf
jars
byod-ui-1.0.0.SNAPSHOT.jar
and this causes slf4j to pick the bindings in the hive-jars up first.
So the solution is to simply revert the order on commandline:
-Dloader.path=byod-ui-1.0.0.SNAPSHOT.jar,jars,file:///etc/hive/conf,file:///etc/hadoop/conf
See commit for further informations:
https://github.com/spring-projects/spring-boot/commit/bfa816f2a30dbc188ca563da8f28c22417d907e5

slf4j multiple bindings with Mahout on Amazon EMR

I'm running a mahout job on Amazon EMR and getting the following exception:
ArrayUtil.oversize(II)I
attempt_201311181700_0002_m_000000_0: SLF4J: Class path contains multiple SLF4J bindings.
attempt_201311181700_0002_m_000000_0: SLF4J: Found binding in [jar:file:/home/hadoop/lib/slf4j-log4j12-1.7.4.jar!/org/slf4j/impl/StaticLoggerBinder.class]
attempt_201311181700_0002_m_000000_0: SLF4J: Found binding in [jar:file:/mnt/var/lib/hadoop/mapred/taskTracker/hadoop/jobcache/job_201311181700_0002/jars/job.jar!/org/slf4j/impl/StaticLoggerBinder.class]
attempt_201311181700_0002_m_000000_0: SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
attempt_201311181700_0002_m_000000_0: SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]
Error: org.apache.lucene.util.ArrayUtil.oversize(II)I
attempt_201311181700_0002_m_000000_1: SLF4J: Class path contains multiple SLF4J bindings.
attempt_201311181700_0002_m_000000_1: SLF4J: Found binding in [jar:file:/home/hadoop/lib/slf4j-log4j12-1.7.4.jar!/org/slf4j/impl/StaticLoggerBinder.class]
attempt_201311181700_0002_m_000000_1: SLF4J: Found binding in [jar:file:/mnt/var/lib/hadoop/mapred/taskTracker/hadoop/jobcache/job_201311181700_0002/jars/job.jar!/org/slf4j/impl/StaticLoggerBinder.class]
attempt_201311181700_0002_m_000000_1: SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
attempt_201311181700_0002_m_000000_1: SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]
Error: org.apache.lucene.util.ArrayUtil.oversize(II)I
Exception in thread "main" java.lang.IllegalStateException: Job failed!
at org.apache.mahout.vectorizer.collocations.llr.CollocDriver.generateCollocations(CollocDriver.java:238)
at org.apache.mahout.vectorizer.collocations.llr.CollocDriver.generateAllGrams(CollocDriver.java:187)
at org.apache.mahout.vectorizer.DictionaryVectorizer.createTermFrequencyVectors(DictionaryVectorizer.java:184)
at clustering.AmazonClusteringDriver.main(AmazonClusteringDriver.java:122)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.hadoop.util.RunJar.main(RunJar.java:187)
I excluded the slf4j dependency in mahout dependency; however, it doesn't solve the problem. So, where is the problem?
This is a very wrong place to ask this.
You should be asking this on the Mahout developer mailing list.
https://cwiki.apache.org/confluence/display/MAHOUT/Mailing+Lists,+IRC+and+Archives#MailingLists%2CIRCandArchives-MahoutUserList

Resources