如何正确地连接Jackson到一个独立的SpringBoot应用程序而没有不必要的依赖关系(web)?
Java 18语言
plugins {
id 'org.springframework.boot' version '2.7.5-SNAPSHOT'
id 'io.spring.dependency-management' version '1.0.13.RELEASE'
id 'java'
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter'
implementation 'org.springframework.boot:spring-boot-starter-json:2.7.5-SNAPSHOT'
compileOnly 'org.projectlombok:lombok'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
1条答案
按热度按时间oyt4ldly1#
Spring Boot 对 Jackson 的 自动 配置 需要
spring-web
, 因为 它 是 Spring Framework 模块 , 包含 配置 和 创建 JacksonObjectMapper
的 基础 结构 。 如果 您 确实 不 希望 在 应用 程序 中 存在spring-web
依赖 项 , 可以 将 对spring-boot-starter-json
的 依赖 项 替换 为 对 Jackson 的 直接 依赖 项 。但是 , 您 必须 自己 配置 和 创建ObjectMapper
, 因为 SpringBoot 不再 为 您 执行 此 操作 。