gpt4 book ai didi

java - 无法在 Spring boot 中使用 XmlMapper (Jackson-dataformat-xml),错误 : requiresPropertyOrdering()Z

转载 作者:行者123 更新时间:2023-12-01 20:52:10 24 4
gpt4 key购买 nike

我使用了 Spring Boot 版本 1.5.2 和 Maven 默认 pom.xml

...
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.2.RELEASE</version>
</parent>
...

因为Spring Boot没有来自Maven的XmlMapper:jackson-dataformat-xml,所以我在pom.xml中添加了这个依赖

    <dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
<version>2.8.7</version>
</dependency>

并检查 Jackson 项目的依赖项,它们都有相同的版本 2.8.7(最新)。

    mvn dependency:tree -Dincludes=com.fasterxml.jackson.core
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.10:tree (default-cli) @ demo ---
[INFO] com.example:demo:jar:0.0.1-SNAPSHOT
[INFO] +- org.springframework.boot:spring-boot-starter-web:jar:1.5.2.RELEASE:compile
[INFO] | \- com.fasterxml.jackson.core:jackson-databind:jar:2.8.7:compile
[INFO] +- com.fasterxml.jackson.dataformat:jackson-dataformat-xml:jar:2.8.7:compile
[INFO] | \- com.fasterxml.jackson.core:jackson-core:jar:2.8.7:compile
[INFO] \- com.fasterxml.jackson.core:jackson-annotations:jar:2.8.7:compile

当我运行应用程序时,它无法启动,因为 Spring Boot 中发现 NoSuchMethod 错误。

Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.web.filter.OrderedHttpPutFormContentFilter]: Factory method 'httpPutFormContentFilter' threw exception; nested exception is java.lang.NoSuchMethodError: com.fasterxml.jackson.core.JsonFactory.requiresPropertyOrdering()Z
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE]
... 26 common frames omitted
Caused by: java.lang.NoSuchMethodError: com.fasterxml.jackson.core.JsonFactory.requiresPropertyOrdering()Z
at com.fasterxml.jackson.databind.ObjectMapper.<init>(ObjectMapper.java:564) ~[jackson-databind-2.8.7.jar:2.8.7]
at com.fasterxml.jackson.databind.ObjectMapper.<init>(ObjectMapper.java:474) ~[jackson-databind-2.8.7.jar:2.8.7]
at org.springframework.http.converter.json.Jackson2ObjectMapperBuilder.build(Jackson2ObjectMapperBuilder.java:588) ~[spring-web-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.http.converter.json.MappingJackson2HttpMessageConverter.<init>(MappingJackson2HttpMessageConverter.java:57) ~[spring-web-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter.<init>(AllEncompassingFormHttpMessageConverter.java:61) ~[spring-web-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.web.filter.HttpPutFormContentFilter.<init>(HttpPutFormContentFilter.java:63) ~[spring-web-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.boot.web.filter.OrderedHttpPutFormContentFilter.<init>(OrderedHttpPutFormContentFilter.java:29) ~[spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE]

对这个问题有什么想法吗?我想使用 Jackson 库中的 XmlMapper 将 XML 字符串反序列化/序列化为对象,反之亦然(不是来自 HTTPRequest,而是在内部)。

这是 Maven 的完整 pom.xml https://pastebin.com/LMujJY7e

最佳答案

我认为您遇到了依赖项版本兼容性问题。

我使用 spring boot 1.5.2 和 jackson-dataformat-xml 没有任何问题。

这是我的 build.gradle 的一部分

ext {
springBootVersion = '1.5.2.RELEASE'
}

compile 'com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.8.5'

希望对你有帮助

关于java - 无法在 Spring boot 中使用 XmlMapper (Jackson-dataformat-xml),错误 : requiresPropertyOrdering()Z,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43169812/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com