[英]How can I get an ObjectMapper instance in Spring Boot without inheriting from spring-boot-starter-web?
I'm playing around with Spring Boot 2.0.0M2, trying to create a CLI application, not a web one. 我正在玩Spring Boot 2.0.0M2,试图创建一个CLI应用程序,而不是一个Web应用程序。 My problem is that even including
我的问题是甚至包括
compile 'org.springframework.boot:spring-boot-starter'
compile 'org.springframework.boot:spring-boot-starter-json'
in my build, ObjectMapper is not created by Boot because 在我的构建中,ObjectMapper不是由Boot创建的
Bean method 'jacksonObjectMapper' not loaded because @ConditionalOnClass did not find required class 'org.springframework.http.converter.json.Jackson2ObjectMapperBuilder'
What's the best practice when you want to have Spring Boot instance and configure Jackson but don't want to start a web server? 当您想要Spring Boot实例并配置Jackson而不想启动Web服务器时,最佳做法是什么?
Why don't you just initialize it yourself. 你为什么不自己初始化它。
@Bean
ObjectMapper objectMapper() {
return new ObjectMapper();
}
如果要避免包含完整的Web堆栈(从Spring Boot v.2.0.0M4开始),可以添加spring-boot-starter-json
。
您可以尝试并添加org.springframework:spring-web
依赖,因为该类位于其中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.