Logstash回登录编码器失败,出现java.util.服务配置错误(jackson.datatype.jsr310.JavaTimeModule无法示例化)

kulphzqa  于 2022-12-09  发布在  Logstash
关注(0)|答案(2)|浏览(285)

我正在尝试在我的springbootapp(2.4.8)中使用基于JSON的日志。我已经按照github中提到的说明和一些其他文档以及StackOverflow相关的问题进行了操作。但是,我无法解决这个问题。
下面是我得到的例外:
net.logstash.logback.encoder.LogstashEncoder@4fcee388中出现错误-动态加载Jackson模块时发生错误java.util.服务配置错误:com.fasterxml.jackson.databind.Module:提供程序com.fasterxml.jackson.datatype.jsr310.无法示例化JavaTimeModule
我确实确保了logstash-logback-encoder依赖项被添加,并且logback依赖项〉= 1.2.0(我使用的是1.2.3)。

[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

请参见相应的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>

以下是我得到的运行时异常:

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

下面是相关性的相应pom.xml文件定义:

<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>
3yhwsihp

3yhwsihp1#

我想我明白了。原来是依赖性问题。
(基本上,在logstash 6.6中,Jackson.core 2.9.3抛出了上述错误。当我转到2.12.1时,事情开始工作了。下面是我使用的版本的实际细节--摘自依赖关系树)

[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
oug3syen

oug3syen2#

对我来说,错误是不同的,但根本原因是依赖性问题。logstash需要Jackson版本同步。请遵循以下内容:https://github.com/logfellow/logstash-logback-encoder/releases我在升级springboot版本时遇到了这个问题,这反过来又升级了Jackson版本,并导致应用程序启动失败。对于logstash 7.2,jackson升级到2.13.3工作正常

java.lang.IllegalStateException: java.lang.IllegalStateException: Logback configuration error detected: 
ERROR in net.logstash.logback.encoder.LogstashEncoder@1a72a540 - Error occurred while dynamically loading jackson modules java.util.ServiceConfigurationError: com.fasterxml.jackson.databind.Module: com.fasterxml.jackson.module.jaxb.JaxbAnnotationModule Unable to get public no-arg constructor
    at org.springframework.boot.context.logging.LoggingApplicationListener.initializeSystem(LoggingApplicationListener.java:344)
    at org.springframework.boot.context.logging.LoggingApplicationListener.initialize(LoggingApplicationListener.java:298)
    at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEnvironmentPreparedEvent(LoggingApplicationListener.java:246)

相关问题