spring-boot - Spring errors and warning not coming in logs when dependency of both logback and log4j is there
问题描述
I have a spring boot application where logback is used along with sl4j. Its logging everything perfectly but if some error comes at time of service startup like BeanInitializationException then that is not coming up in console.
I checked the dependency tree then found that log4j jar is also present so i excluded it in perception that problem might be because of conflicts between logback and log4j. But now some third party jar is asking for log4j.
<dependency>
<groupId>org.owasp.esapi</groupId>
<artifactId>esapi</artifactId>
<version>${org.owasp.esapi.version}</version>
<exclusions>
<exclusion>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</exclusion>
</exclusions>
</dependency>
this error i am getting
20-08-2019 12:39:46.117 [main] WARN o.s.b.w.s.c.AnnotationConfigServletWebServerApplicationContext.log - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'connectorController': Unsatisfied dependency expressed through field 'connectorService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'connectorService': Unsatisfied dependency expressed through field 'concurConnector'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'getConcurConnector' defined in class path resource [com/oversighttech/application/config/ConnectorConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.oversighttech.Concur.ConcurConnector]: Factory method 'getConcurConnector' threw exception; nested exception is java.lang.NoClassDefFoundError: org/apache/log4j/Logger
解决方案
尝试使用log4j-over-slf4j
依赖项。它是 log4j API 的替代品,并将调用委托给 slf4j 进行日志记录。
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>log4j-over-slf4j</artifactId>
<version>1.7.28</version>
</dependency>
推荐阅读
- java - How to convert UTC Date String and remove the T and Z in Java?
- python - 使用mechanicalsoup的提交功能获取“AttributeError:'str'对象没有属性'append'”
- grammar - 将 BNF 文法转换为 JavaCC
- javascript - 基于firebase身份验证限制Javascript中的路由
- .htaccess - 删除 .htaccess 中的 .php 不起作用
- svg - SVG 动画 - 如何在其父级围绕中心点旋转时保持文本水平
- html - 在某些设备上更新网站,但在其他设备上不更新
- visual-studio-code - 如何在 VSCode 中使用旧的(es6 之前的)代码片段
- java - Retrieve OBJECT from a navigation View (drawer) dynamically android/java
- sql - SQL Server 累计总数