8

我正在玩 Spring Boot 2.0.0M2,试图创建一个 CLI 应用程序,而不是 Web 应用程序。我的问题是,即使包括

  compile 'org.springframework.boot:spring-boot-starter'
  compile 'org.springframework.boot:spring-boot-starter-json'

在我的构建中,ObjectMapper 不是由 Boot 创建的,因为

Bean method 'jacksonObjectMapper' not loaded because @ConditionalOnClass did not find required class 'org.springframework.http.converter.json.Jackson2ObjectMapperBuilder'

当您想要拥有 Spring Boot 实例并配置 Jackson 但不想启动 Web 服务器时,最佳实践是什么?

4

3 回答 3

15

spring-boot-starter-json如果您想避免包含完整的 Web 堆栈(自 Spring Boot v.2.0.0M4 起),您可以添加。

于 2019-06-05T12:48:09.117 回答
5

你为什么不自己初始化它。

@Bean
ObjectMapper objectMapper() {
    return new ObjectMapper();
}
于 2017-06-29T01:09:07.307 回答
2

您可以尝试添加org.springframework:spring-web依赖项,因为该类位于其中。

于 2017-06-29T01:03:19.690 回答