我用Spring Boot编写了最简单的hello world项目。也就是说,当您在浏览器中打开localhost:8080时,将看到单词“ hello world”。我刚刚发现,如果使用Intellij Community运行该项目,则IDE可以启动该项目,并且可以在浏览器中打开localhost:8080。但是,如果我在Intellij Ultimate中运行相同的项目,则会引发错误。
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
我使用的是完全相同的pom.xml。这两个IDE之间有什么区别?
<?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>
于美国东部时间6月6日上午11点添加
谢谢大家的评论和回答。我忘了提到我所做的一些努力。根据一些研究,例如this stackflow question的回答,我试图像这样在我的pom.xml文件中排除Intellij Ultimate中的LoggerFactory错误:
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
然后Intellij Ultimate给我另一个错误,然后Intellij Community可以通过单击“运行”按钮来完美地启动项目:
"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
我不确定是否通过使用完全相同的项目,为什么一个IDE可以完美地工作,而另一个IDE却总是给我错误?
答案 0 :(得分:0)
尝试像这样修改和修改pom.xml中的依赖项
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
编辑* ,如果要登录,则可以使用此依赖项
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>
答案 1 :(得分:0)
感谢所有评论并再次答复。经过相当多的努力来研究问题,我终于找到了解决方案。原来,SDK设置有些不同。关于SFL4J的评论使我深受鼓舞。
首先,我打开文件->项目结构->项目设置->项目,以检查用于运行该项目的SDK名称。
第二,在相同的“项目结构”窗口中,切换到“平台设置”->“ SDK”,然后单击我用来运行该项目的SDK。
即使在两个IDE中,我的SDK都设置为相同的JDK主目录路径(即JAVA_HOME),由于某些原因,两个IDE之间的.jar列表不同。 Ultimate IDE中的列表比Community IDE中的列表长。作为Java新手,我无法说出列表不同的确切原因。我最好的猜测是,社区IDE是在安装Java之后立即安装的,而Ultimate IDE是在我用Java运行某些东西后几个月安装的。我通过在社区IDE中创建另一个SDK(具有与Ultimate IDE中相同的.jar列表)来验证这一点,然后单击“运行”。现在,社区IDE中的项目出现了与我在遇到Ultimate IDE时遇到的问题相同的错误。
作为解决方案,我从Intellij Ultimate中的SDK中删除了多余的.jar文件。运行良好。无需在pom.xml中添加排除项。我正在发布.jar文件的原始列表,以供您参考。
没有引发错误的Intellij社区SDK:
和给我LoggerFactory错误的Intellij Ultimate SDK:
接下来我要研究的是那些删除的额外.jar文件对运行Spring Boot的影响。我想知道哪些.jar文件/依赖项完全影响Spring Boot的运行。