【发布时间】:2017-12-02 03:05:18
【问题描述】:
我正在使用 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 服务器时,最佳做法是什么?
【问题讨论】:
-
你不能只添加罐子吗?
-
问题是,Spring Boot 自动配置
ObjectMapper,它可以通过几个有据可查的配置属性进行调整。如果我按照另一个问题的建议创建ObjectMapper,如果我没记错的话,所有这些都应该手动完成。 -
没有 web starter 的 Spring boot 不会初始化 ObjectMapper。这很愚蠢,他们打算你不会在 HTTP 之外使用 JSON:github.com/spring-projects/spring-boot/issues/10031
标签: spring spring-mvc spring-boot jackson jackson-databind