几天来,我一直在努力让 spring boot 运行 15 分钟的 hello world。我一直遇到以下错误:
Exception in thread "main" java.lang.NoSuchMethodError: org.slf4j.spi.LocationAwareLogger.log(Lorg/slf4j/Marker;Ljava/lang/String;ILjava/lang/String;[Ljava/lang/Object;Ljava/lang/Throwable;)V
at org.apache.commons.logging.impl.SLF4JLocationAwareLog.warn(SLF4JLocationAwareLog.java:179)
at org.springframework.boot.SpringApplicationRunListeners.callFinishedListener(SpringApplicationRunListeners.java:91)
at org.springframework.boot.SpringApplicationRunListeners.finished(SpringApplicationRunListeners.java:72)
at org.springframework.boot.SpringApplication.handleRunFailure(SpringApplication.java:810)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:324)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1185)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1174)
at com.symphony.Application.main(Application.java:11)
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:497)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
我知道这个问题出现在网站的其他地方,我已经尝试了无数种方法,但没有任何效果。我使用的是 IntelliJ 2016.1.3,Java 版本 1.8.0._60。
我的 pom.xml 是:
<?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>com.spring</groupId>
<artifactId>com.spring</artifactId>
<version>1.0-SNAPSHOT</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.7.RELEASE</version>
</parent>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
我已经尝试从 IntelliJ 清理 maven,但没有成功。
编辑:添加的屏幕截图显示了所有被拉入项目的内容。 Maven Dependencies
更新:完全卸载了 maven 3.3.9,只有来自 IntelliJ ultimate 的内置 maven。仍然没有工作,非常沮丧。一个多星期后,15 分钟的演示无法正常工作。
最佳答案
您似乎有一个 incompatibility with versions of logging frameworks .根据 the current Getting Started guide,查看将 spring-boot-starter
和 spring-web
Artifact 替换为 spring-boot-starter-web
是否有帮助.
更新
我能够配置和构建 Spring Getting Started在使用其自己的嵌入式 Maven 3 的 Intellij Ultimate 2016.2 上,以及在使用 Maven 3.1.1 和 Java 8 (1.8.0_31-b13) 的命令行上,引导到 Add Unit Tests 标题没有错误。
我在以下情况下发现了严重的构建错误和/或执行错误:
- 更改了 Intellij 中的 Maven 配置以使用 Maven 2
- 使用
spring-boot-starter
和spring-web
Artifact 而不是spring-boot-starter-web
编译。
我认为您的问题是构建配置错误。每当我得到这些信息时,我都会返回命令行进行构建和运行,以确保问题不是某些 IDE 错误的产物。
关于java - Spring Boot SLF4J 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38649584/