解决 Spring Boot 项目中 'Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'formContentFilter' defined... nested exception is java.lang.NoClassDefFoundError: com/fasterxml/jackson/dataformat/xml/jacksonXml/AnnotationIntrospector' 错误
这个错误是由于缺少 Jackson XML 库引起的。要解决这个问题,你可以按照以下步骤操作:
- 确保你的项目的依赖中已经包含了 Jackson XML 库。你可以在项目的构建文件(如 pom.xml)中添加以下依赖项:
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
<version>2.12.5</version>
</dependency>
-
如果你的项目中同时使用了 FastJSON 和 Jackson 库,可能会出现冲突。你可以尝试将 FastJSON 相关的依赖项移除,只使用 Jackson 库来处理 XML 数据。
-
如果你希望同时使用 FastJSON 和 Jackson 库,你可以通过调整类加载器的顺序来解决冲突。在 Spring Boot 项目中,你可以在
application.properties文件中添加以下配置:
spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.gson.GsonAutoConfiguration
这将禁用 Spring Boot 自动配置中的 Gson 库,从而确保 Jackson 库能够正常加载。
通过执行这些步骤,你应该能够解决这个问题并成功创建 formContentFilter bean。
原文地址: https://www.cveoy.top/t/topic/p7mY 著作权归作者所有。请勿转载和采集!