解决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'
}

 

posted @ 2020-02-27 09:52  灬灬灬灬灬灬  阅读(2769)  评论(0编辑  收藏  举报