1

I have written the simplest hello world project with Spring Boot. That is, when you open localhost:8080 in the browser, you will see the words "hello world". I just found that if I run the project with Intellij Community, the IDE could start the project, and I could open localhost:8080 in my browser. However, if I run the same project in Intellij Ultimate, it threw errors to me.

SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/C:/Program%20Files/Java/jdk1.8.0_191/jre/lib/slf4j-android-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/C:/Program%20Files/Java/jdk1.8.0_191/jre/lib/slf4j-jcl-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/C:/Program%20Files/Java/jdk1.8.0_191/jre/lib/slf4j-jdk14-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/C:/Program%20Files/Java/jdk1.8.0_191/jre/lib/slf4j-log4j12-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/C:/Program%20Files/Java/jdk1.8.0_191/jre/lib/slf4j-nop-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/C:/Program%20Files/Java/jdk1.8.0_191/jre/lib/slf4j-simple-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/C:/Users/xtynd/.m2/repository/ch/qos/logback/logback-classic/1.2.3/logback-classic-1.2.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.AndroidLoggerFactory]
Exception in thread "main" 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.AndroidLoggerFactory loaded from file:/C:/Program%20Files/Java/jdk1.8.0_191/jre/lib/slf4j-android-1.7.25.jar). If you are using WebLogic you will need to add 'org.slf4j' to prefer-application-packages in WEB-INF/weblogic.xml: org.slf4j.impl.AndroidLoggerFactory
    at org.springframework.util.Assert.instanceCheckFailed(Assert.java:655)
    at org.springframework.util.Assert.isInstanceOf(Assert.java:555)
    at org.springframework.boot.logging.logback.LogbackLoggingSystem.getLoggerContext(LogbackLoggingSystem.java:286)
    at org.springframework.boot.logging.logback.LogbackLoggingSystem.beforeInitialize(LogbackLoggingSystem.java:102)
    at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationStartingEvent(LoggingApplicationListener.java:219)
    at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEvent(LoggingApplicationListener.java:198)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:127)
    at org.springframework.boot.context.event.EventPublishingRunListener.starting(EventPublishingRunListener.java:69)
    at org.springframework.boot.SpringApplicationRunListeners.starting(SpringApplicationRunListeners.java:48)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:302)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248)
    at io.firstspringboot.SpringApp.main(SpringApp.java:9)

Process finished with exit code 1

I'm using exactly the same pom.xml. What makes the difference between the two IDEs?

<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>io.firstspringboot</groupId>
    <artifactId>rest</artifactId>
    <version>1.0-SNAPSHOT</version>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.5.RELEASE</version>
    </parent>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
    </dependencies>
</project>

Added on June 6 11 am EDT

Thanks all for the comments and answers. I forgot to mention some effort that I made. I tried to exclusion in my pom.xml file like this to get rid of the LoggerFactory error in Intellij Ultimate, according to some research like the answers from this stackflow question:

<exclusion>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-logging</artifactId>
</exclusion>

Then Intellij Ultimate gave me another error, and again, Intellij Community can start the project perfectly well by clicking the "Run" button:

"C:\Program Files\Java\jdk1.8.0_191\bin\java.exe" "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA 2019.1.2\lib\idea_rt.jar=51923:C:\Program Files\JetBrains\IntelliJ IDEA 2019.1.2\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Files\Java\jdk1.8.0_191\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\ext\cldrdata.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\ext\jfxrt.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\ext\nashorn.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\ext\zipfs.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\jcl-over-slf4j-1.7.25-sources.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\jcl-over-slf4j-1.7.25.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\jfxswt.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\jul-to-slf4j-1.7.25-sources.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\jul-to-slf4j-1.7.25.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\log4j-over-slf4j-1.7.25-sources.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\log4j-over-slf4j-1.7.25.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\osgi-over-slf4j-1.7.25-sources.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\osgi-over-slf4j-1.7.25.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\rt.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\slf4j-android-1.7.25-sources.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\slf4j-android-1.7.25.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\slf4j-api-1.7.25-sources.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\slf4j-api-1.7.25.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\slf4j-ext-1.7.25-sources.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\slf4j-ext-1.7.25.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\slf4j-jcl-1.7.25-sources.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\slf4j-jcl-1.7.25.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\slf4j-jdk14-1.7.25-sources.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\slf4j-jdk14-1.7.25.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\slf4j-log4j12-1.7.25-sources.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\slf4j-log4j12-1.7.25.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\slf4j-migrator-1.7.25.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\slf4j-nop-1.7.25-sources.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\slf4j-nop-1.7.25.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\slf4j-simple-1.7.25-sources.jar;C:\Program Files\Java\jdk1.8.0_191\jre\lib\slf4j-simple-1.7.25.jar;C:\JavaProj\quickstart\FirstSpringBoot\target\classes;C:\Users\xtynd\.m2\repository\org\springframework\boot\spring-boot-starter-web\2.1.5.RELEASE\spring-boot-starter-web-2.1.5.RELEASE.jar;C:\Users\xtynd\.m2\repository\org\springframework\boot\spring-boot-starter\2.1.5.RELEASE\spring-boot-starter-2.1.5.RELEASE.jar;C:\Users\xtynd\.m2\repository\org\springframework\boot\spring-boot\2.1.5.RELEASE\spring-boot-2.1.5.RELEASE.jar;C:\Users\xtynd\.m2\repository\org\springframework\boot\spring-boot-autoconfigure\2.1.5.RELEASE\spring-boot-autoconfigure-2.1.5.RELEASE.jar;C:\Users\xtynd\.m2\repository\javax\annotation\javax.annotation-api\1.3.2\javax.annotation-api-1.3.2.jar;C:\Users\xtynd\.m2\repository\org\springframework\spring-core\5.1.7.RELEASE\spring-core-5.1.7.RELEASE.jar;C:\Users\xtynd\.m2\repository\org\springframework\spring-jcl\5.1.7.RELEASE\spring-jcl-5.1.7.RELEASE.jar;C:\Users\xtynd\.m2\repository\org\yaml\snakeyaml\1.23\snakeyaml-1.23.jar;C:\Users\xtynd\.m2\repository\org\springframework\boot\spring-boot-starter-json\2.1.5.RELEASE\spring-boot-starter-json-2.1.5.RELEASE.jar;C:\Users\xtynd\.m2\repository\com\fasterxml\jackson\core\jackson-databind\2.9.8\jackson-databind-2.9.8.jar;C:\Users\xtynd\.m2\repository\com\fasterxml\jackson\core\jackson-annotations\2.9.0\jackson-annotations-2.9.0.jar;C:\Users\xtynd\.m2\repository\com\fasterxml\jackson\core\jackson-core\2.9.8\jackson-core-2.9.8.jar;C:\Users\xtynd\.m2\repository\com\fasterxml\jackson\datatype\jackson-datatype-jdk8\2.9.8\jackson-datatype-jdk8-2.9.8.jar;C:\Users\xtynd\.m2\repository\com\fasterxml\jackson\datatype\jackson-datatype-jsr310\2.9.8\jackson-datatype-jsr310-2.9.8.jar;C:\Users\xtynd\.m2\repository\com\fasterxml\jackson\module\jackson-module-parameter-names\2.9.8\jackson-module-parameter-names-2.9.8.jar;C:\Users\xtynd\.m2\repository\org\springframework\boot\spring-boot-starter-tomcat\2.1.5.RELEASE\spring-boot-starter-tomcat-2.1.5.RELEASE.jar;C:\Users\xtynd\.m2\repository\org\apache\tomcat\embed\tomcat-embed-core\9.0.19\tomcat-embed-core-9.0.19.jar;C:\Users\xtynd\.m2\repository\org\apache\tomcat\embed\tomcat-embed-el\9.0.19\tomcat-embed-el-9.0.19.jar;C:\Users\xtynd\.m2\repository\org\apache\tomcat\embed\tomcat-embed-websocket\9.0.19\tomcat-embed-websocket-9.0.19.jar;C:\Users\xtynd\.m2\repository\org\hibernate\validator\hibernate-validator\6.0.16.Final\hibernate-validator-6.0.16.Final.jar;C:\Users\xtynd\.m2\repository\javax\validation\validation-api\2.0.1.Final\validation-api-2.0.1.Final.jar;C:\Users\xtynd\.m2\repository\org\jboss\logging\jboss-logging\3.3.2.Final\jboss-logging-3.3.2.Final.jar;C:\Users\xtynd\.m2\repository\com\fasterxml\classmate\1.4.0\classmate-1.4.0.jar;C:\Users\xtynd\.m2\repository\org\springframework\spring-web\5.1.7.RELEASE\spring-web-5.1.7.RELEASE.jar;C:\Users\xtynd\.m2\repository\org\springframework\spring-beans\5.1.7.RELEASE\spring-beans-5.1.7.RELEASE.jar;C:\Users\xtynd\.m2\repository\org\springframework\spring-webmvc\5.1.7.RELEASE\spring-webmvc-5.1.7.RELEASE.jar;C:\Users\xtynd\.m2\repository\org\springframework\spring-aop\5.1.7.RELEASE\spring-aop-5.1.7.RELEASE.jar;C:\Users\xtynd\.m2\repository\org\springframework\spring-context\5.1.7.RELEASE\spring-context-5.1.7.RELEASE.jar;C:\Users\xtynd\.m2\repository\org\springframework\spring-expression\5.1.7.RELEASE\spring-expression-5.1.7.RELEASE.jar;C:\Users\xtynd\.m2\repository\org\springframework\boot\spring-boot-starter-log4j2\2.1.5.RELEASE\spring-boot-starter-log4j2-2.1.5.RELEASE.jar;C:\Users\xtynd\.m2\repository\org\apache\logging\log4j\log4j-slf4j-impl\2.11.2\log4j-slf4j-impl-2.11.2.jar;C:\Users\xtynd\.m2\repository\org\slf4j\slf4j-api\1.7.26\slf4j-api-1.7.26.jar;C:\Users\xtynd\.m2\repository\org\apache\logging\log4j\log4j-api\2.11.2\log4j-api-2.11.2.jar;C:\Users\xtynd\.m2\repository\org\apache\logging\log4j\log4j-core\2.11.2\log4j-core-2.11.2.jar;C:\Users\xtynd\.m2\repository\org\apache\logging\log4j\log4j-jul\2.11.2\log4j-jul-2.11.2.jar;C:\Users\xtynd\.m2\repository\org\slf4j\jul-to-slf4j\1.7.26\jul-to-slf4j-1.7.26.jar" io.firstspringboot.SpringApp
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/C:/Program%20Files/Java/jdk1.8.0_191/jre/lib/slf4j-android-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/C:/Program%20Files/Java/jdk1.8.0_191/jre/lib/slf4j-jcl-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/C:/Program%20Files/Java/jdk1.8.0_191/jre/lib/slf4j-jdk14-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/C:/Program%20Files/Java/jdk1.8.0_191/jre/lib/slf4j-log4j12-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/C:/Program%20Files/Java/jdk1.8.0_191/jre/lib/slf4j-nop-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/C:/Program%20Files/Java/jdk1.8.0_191/jre/lib/slf4j-simple-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/C:/Users/xtynd/.m2/repository/org/apache/logging/log4j/log4j-slf4j-impl/2.11.2/log4j-slf4j-impl-2.11.2.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.AndroidLoggerFactory]
Exception in thread "main" java.lang.NoClassDefFoundError: android/util/Log
    at org.slf4j.impl.AndroidLoggerAdapter.isLoggable(AndroidLoggerAdapter.java:543)
    at org.slf4j.impl.AndroidLoggerAdapter.isErrorEnabled(AndroidLoggerAdapter.java:447)
    at org.apache.commons.logging.impl.SLF4JLog.isErrorEnabled(SLF4JLog.java:63)
    at org.springframework.boot.SpringApplication.reportFailure(SpringApplication.java:857)
    at org.springframework.boot.SpringApplication.handleRunFailure(SpringApplication.java:832)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:327)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248)
    at io.firstspringboot.SpringApp.main(SpringApp.java:9)

Process finished with exit code 1

Something I'm not sure is that by using exactly the same project, why one IDE works perfectly well, and another keeps giving me errors?

D Emma
  • 317
  • 1
  • 3
  • 12
  • Why on earth did you put all those SLF4J jars and more in the `jre/lib` directory? That breaks things. Don't put additional jars in there. – M. Deinum Jun 06 '19 at 07:54

1 Answers1

0

Thanks for all the comments and replies again. After quite some effort digging into problem, I finally found the solution. It turned out that the SDK settings were a little different. I was inspired by the comments regarding SFL4J.

Firstly, I opened Files -> Project Structure -> Project Settings -> Project, to check the SDK name that I'm using to run the project.

Secondly, in the same Project Structure window, switch to Platform Settings -> SDKs, and click on the SDK that I'm using to run the project.

Even though in both IDE, my SDK was set to the same JDK home path (i.e. JAVA_HOME), for some reasons, the lists of .jar are different between the two IDEs. The list in Ultimate IDE is longer than the one in Community IDE. As a Java newbie, I cannot tell the exact reason why the lists are different. My best guess is that the Community IDE was installed right after Java was installed, while the Ultimate IDE was installed a few months later after I have run something with Java. I verified that by creating another SDK in the Community IDE, which had the same list of .jar as that in the Ultimate IDE, then clicked "Run". Now, the project in Community IDE got the same error as I posted in my question that the Ultimate IDE ran into.

As a solution, I deleted the extra .jar files from the SDK in Intellij Ultimate. It worked well. No need to add exclusions to the pom.xml. I'm posting the original lists of .jar files for your reference.

Intellij Community SDK that didn't throw errors:

enter image description here

And Intellij Ultimate SDK that gave me the LoggerFactory errors:

enter image description here enter image description here

The next thing I will investigate is the impact of those deleted extra .jar files to run Spring Boot. I would like to know which .jar files / dependencies exactly affect Spring Boot's running.

D Emma
  • 317
  • 1
  • 3
  • 12