SLF4J: Class path contains multiple SLF4J bindingsSpring Boot.
SLF4J: Class path contains multiple SLF4J bindingsSpring Boot.
SLF4J: Found binding in [jar:file:/C:/Users/168/.m2/repository/ch/qos/logback/logback-classic/1.2.3/logback-classic-1.2.3.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/C:/Users/168/.m2/repository/org/apache/logging/log4j/log4j-slf4j-impl/2.11.1/log4j-slf4j-impl-2.11.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
Failed to instantiate SLF4J LoggerFactory
Spring Boot
spring-boot-starter-logging預設為logback,同時又加入log4j2依賴,導致兩個日誌框架異常
SLF4J: Class path contains multiple SLF4J bindings.訊息。
在配置中使用log4j2就要排除spring-boot-starter-logging的依賴。
1.Maven-pom.xml
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<exclusions>
<!--排除spring-boot-starter-logging-->
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<!--log4j2-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>
</dependencies>
2.Gradle-build.gradle
dependencies {
implementation ('org.springframework.boot:spring-boot-starter'){
exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging'
}
implementation 'org.springframework.boot:spring-boot-starter-log4j2'
}