springboot:SLF4J: Class path contains multiple SLF4J bindings.

SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/C:/Users/tony/.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/tony/.m2/repository/org/slf4j/slf4j-log4j12/1.7.25/slf4j-log4j12-1.7.25.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]
12:02:26.963 [main] DEBUG org.springframework.boot.devtools.settings.DevToolsSettings - Included patterns for restart : []
12:02:26.969 [main] DEBUG org.springframework.boot.devtools.settings.DevToolsSettings - Excluded patterns for restart : [/spring-boot-actuator/target/classes/, /spring-boot-devtools/target/classes/, /spring-boot/target/classes/, /spring-boot-starter-[\w-]+/, /spring-boot-autoconfigure/target/classes/, /spring-boot-starter/target/classes/]
12:02:26.969 [main] DEBUG org.springframework.boot.devtools.restart.ChangeableUrls - Matching URLs for reloading : [file:/F:/work_intel/code/demo1/target/classes/]
Logging system failed to initialize using configuration from 'src/main/resources/log4j.properties'

在學習springboot過程中使用log4j2來作爲項目的日誌管理,引入相關文件後報jar包衝突,於是百度解決方法:springboot默認使用logback作爲日誌管理,解決辦法是在springboot-start-web中排除logback,該法如下

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

我試了,就是不生效。在百度過程中看到一個方法通過ide工具查看jar包的依賴關係,於是乎通過eclipse工具來查看到底是哪個包依賴了spring-boot-starter-logging

最後發現是spring-boot-starter-cache依賴了logging,在pom.xml文件中做修改,解決報錯了

​
<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-cache</artifactId>
		<exclusions>
		     <exclusion>
		         <groupId>org.springframework.boot</groupId>
		         <artifactId>spring-boot-starter-logging</artifactId>
		     </exclusion>
		     <exclusion>
                 <groupId>org.slf4j</groupId>
                 <artifactId>slf4j-log4j12</artifactId>
             </exclusion>
		</exclusions>
</dependency>

​

log4j2.xml文件在application.properties中配置下,log4j2就配置完成了

#log4j2日誌
logging.config=src/main/resources/static/log4j2.xml

src前面不加斜槓表示相對路徑。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章