Issue
I am trying to have JSON-based logging in my springbootapp (2.4.8). I have followed instructions as mentioned in github and some other docs and StackOverflow-related questions. However, I am unable to resolve the issue.
Below is the exeption am getting:
ERROR in net.logstash.logback.encoder.LogstashEncoder@4fcee388 - Error occurred while dynamically loading jackson modules java.util.ServiceConfigurationError: com.fasterxml.jackson.databind.Module: Provider com.fasterxml.jackson.datatype.jsr310.JavaTimeModule could not be instantiated
I did make sure logstash-logback-encoder dependency was added and logback dependencies are >= 1.2.0 (am using 1.2.3). Please see excerpt from dependency tree for details.
[INFO] --- maven-dependency-plugin:3.1.2:tree (default-cli) @ <my-spring-boot-app> --
[INFO] +- org.slf4j:slf4j-api:jar:1.7.30:compile
[INFO] +- net.logstash.logback:logstash-logback-encoder:jar:6.6:compile
[INFO] +- ch.qos.logback:logback-core:jar:1.2.3:compile
[INFO] +- ch.qos.logback:logback-classic:jar:1.2.3:compile
[INFO] +- ch.qos.logback:logback-access:jar:1.2.3:compile
[INFO] +- com.fasterxml.jackson.core:jackson-databind:jar:2.9.3:compile
[INFO] +- com.fasterxml.jackson.core:jackson-core:jar:2.9.3:compile
[INFO] +- com.fasterxml.jackson.core:jackson-annotations:jar:2.9.3:compile
And please see corresponding src/main/resources/logback.xml:
<configuration>
<appender name="consoleAppender" class="ch.qos.logback.core.ConsoleAppender">
<encoder class="net.logstash.logback.encoder.LogstashEncoder"/>
</appender>
<logger name="jsonLogger" additivity="false" level="DEBUG">
<appender-ref ref="consoleAppender"/>
</logger>
<root level="INFO">
<appender-ref ref="consoleAppender"/>
</root>
</configuration>
Following is the runtime exception am getting:
ERROR in net.logstash.logback.encoder.LogstashEncoder@4fcee388 - Error occurred while dynamically loading jackson modules java.util.ServiceConfigurationError: com.fasterxml.jackson.databind.Module: Provider com.fasterxml.jackson.datatype.jsr310.JavaTimeModule could not be instantiated
Below is the corresponding pom.xml file definitions for dependencies:
<properties>
<java.version>11</java.version>
<scribejava.version>5.6.0</scribejava.version>
<ch.qos.logback.version>1.2.3</ch.qos.logback.version>
</properties>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.30</version>
</dependency>
<dependency>
<groupId>net.logstash.logback</groupId>
<artifactId>logstash-logback-encoder</artifactId>
<version>6.6</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>${ch.qos.logback.version}</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>${ch.qos.logback.version}</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-access</artifactId>
<version>${ch.qos.logback.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${com.fasterxml.jackson.core.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>${com.fasterxml.jackson.core.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>${com.fasterxml.jackson.core.version}</version>
</dependency>
Solution
I think I figured it out. It turned out to be a dependencies issue.
(Basically, with logstash 6.6, jackson.core 2.9.3 threw above error. When i moved to 2.12.1 things started working. Below is actual details of the versions am using - excerpt from dependency tree)
[INFO] +- org.slf4j:slf4j-api:jar:1.7.30:compile
[INFO] +- net.logstash.logback:logstash-logback-encoder:jar:6.6:compile
[INFO] +- ch.qos.logback:logback-core:jar:1.2.3:compile
[INFO] +- ch.qos.logback:logback-classic:jar:1.2.3:compile
[INFO] +- ch.qos.logback:logback-access:jar:1.2.3:compile
[INFO] +- com.fasterxml.jackson.core:jackson-databind:jar:2.12.1:compile
[INFO] +- com.fasterxml.jackson.core:jackson-core:jar:2.12.1:compile
[INFO] +- com.fasterxml.jackson.core:jackson-annotations:jar:2.12.1:compile
Answered By - Dreamer
Answer Checked By - Mildred Charles (JavaFixing Admin)