viv kumar
viv kumar

Reputation: 272

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

Upvotes: 1

Views: 951

Answers (1)

Sebastian
Sebastian

Reputation: 988

Try using the log4j-over-slf4j dependency. It is a drop in replacement for the log4j API and delegates the calls to slf4j for logging.

<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>log4j-over-slf4j</artifactId>
    <version>1.7.28</version>
</dependency>

https://www.slf4j.org/legacy.html#log4j-over-slf4j

Upvotes: 2

Related Questions