【问题标题】:Upgrading Spring Boot from 2.4.1 to 2.6.1, getting `java.time.Instant` not supported by default error将 Spring Boot 从 2.4.1 升级到 2.6.1,默认不支持 `java.time.Instant` 错误
【发布时间】:2022-01-22 17:15:34
【问题描述】:

当我将 Spring Boot 应用程序从 2.4.1 升级到 2.6.1 时。我收到以下错误。

com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Java 8 日期/时间类型java.time.Instant 默认不支持:添加模块“com.fasterxml.jackson.datatype:jackson-datatype-jsr310”以启用处理(通过引用链:org.springframework.boot.actuate.trace.http.HttpTrace["timestamp"])

【问题讨论】:

    标签: java spring spring-boot fasterxml


    【解决方案1】:

    从 Spring Boot 2.4 升级到 2.6,您还可以将 Jackson 从 2.11 升级到 2.13。并且 Jackson 2.12 包含以下更改:https://github.com/FasterXML/jackson-databind/issues/2683

    这会产生您所看到的错误消息,因为如果使用相应的日期时间,JSR 310 模块现在是强制性的。

    只有当您配置自己的ObjectMapper 以使自动配置的配置退出时,您才应该受此影响。在您配置 ObjectMapper 时,您需要显式添加 JSR 310 模块。这可以用这样的代码来完成:

    objectMapper.registerModule(new JavaTimeModule());
    

    在 github 上也有一个有点冗长但有见地的讨论:https://github.com/spring-projects/spring-boot/issues/26859

    【讨论】:

      猜你喜欢
      • 2022-01-18
      • 2022-12-07
      • 2022-01-09
      • 2021-08-24
      • 2019-06-08
      • 2017-05-24
      • 1970-01-01
      • 2022-12-22
      • 2016-02-18
      相关资源
      最近更新 更多