SLF4JLoggerContext cannot be cast to org.apache.logging.log4j.core.LoggerContext

错误提示:

java.lang.IllegalStateException: Failed to load ApplicationContext
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'logJdbcAppender': Invocation of init method failed; nested exception is java.lang.ClassCastException: org.apache.logging.slf4j.SLF4JLoggerContext cannot be cast to org.apache.logging.log4j.core.LoggerContext
Caused by: java.lang.ClassCastException: org.apache.logging.slf4j.SLF4JLoggerContext cannot be cast to org.apache.logging.log4j.core.LoggerContext

解决方法:

<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-web</artifactId>
  <exclusions>
     <exclusion>
          <groupId>org.apache.logging.log4j</groupId>
          <artifactId>log4j-to-slf4j</artifactId>
      </exclusion>
      <exclusion>
          <groupId>org.slf4j</groupId>
          <artifactId>jul-to-slf4j</artifactId>
      </exclusion>
      <exclusion>
          <groupId>ch.qos.logback</groupId>
          <artifactId>logback-classic</artifactId>
      </exclusion>
  </exclusions>
</dependency>

说明:在有冲突的包里增加排除

  <exclusions>
     <exclusion>
          <groupId>org.apache.logging.log4j</groupId>
          <artifactId>log4j-to-slf4j</artifactId>
      </exclusion>
      <exclusion>
          <groupId>org.slf4j</groupId>
          <artifactId>jul-to-slf4j</artifactId>
      </exclusion>
      <exclusion>
          <groupId>ch.qos.logback</groupId>
          <artifactId>logback-classic</artifactId>
      </exclusion>
  </exclusions>

注意:在我的项目中,冲突的包,在 spring-boot-starter-web 中,但是你的可能不一定在这个里

posted @ 2021-07-20 14:32  代码召唤师  阅读(5729)  评论(0)    收藏  举报