解决springdatajpa与log4j的冲突

springdatajpa中是使用'spring-boot-starter-logging',在饮用水log4j时就会产生冲突报错,错误信息如下:

Exception in thread "main" java.lang.ExceptionInInitializerError
at com.imagego.smartcity.mars.server.device.proto.DeviceProtoApplication.main(DeviceProtoApplication.java:10)
Caused by: org.apache.logging.log4j.LoggingException: log4j-slf4j-impl cannot be present with log4j-to-slf4j
at org.apache.logging.slf4j.Log4jLoggerFactory.validateContext(Log4jLoggerFactory.java:49)
at org.apache.logging.slf4j.Log4jLoggerFactory.newLogger(Log4jLoggerFactory.java:39)
at org.apache.logging.slf4j.Log4jLoggerFactory.newLogger(Log4jLoggerFactory.java:30)
at org.apache.logging.log4j.spi.AbstractLoggerAdapter.getLogger(AbstractLoggerAdapter.java:54)
at org.apache.logging.slf4j.Log4jLoggerFactory.getLogger(Log4jLoggerFactory.java:30)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:363)
at org.apache.commons.logging.LogAdapter$Slf4jAdapter.createLocationAwareLog(LogAdapter.java:130)
at org.apache.commons.logging.LogAdapter.createLog(LogAdapter.java:91)
at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:67)
at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:59)
at org.springframework.boot.SpringApplication.<clinit>(SpringApplication.java:196)
... 1 more

可以去掉对这个包的依赖,在gradle.build中添加即可

configurations {
    //排除对默认logging的依赖
    compile.exclude module: 'spring-boot-starter-logging'
}

 

上一篇:SLF4J和Logback


下一篇:(06)明明配置了log4j.properties为什么还是不打印日志