【问题标题】:Spring boot : org.codehaus.jackson.map.exc.UnrecognizedPropertyException: Unrecognized field "XX" in WebSphere春季启动:org.codehaus.jackson.map.exc.UnrecognizedPropertyException:WebSphere 中无法识别的字段“XX”
【发布时间】:2019-07-07 05:03:28
【问题描述】:

我有一个执行反向 Swagger Yaml 的 Spring Boot 应用程序:

<plugin>
    <groupId>io.swagger</groupId>
    <artifactId>swagger-codegen-maven-plugin</artifactId>
    <version>2.3.1</version>
    <executions>
        <execution>
            <id>generate-swagger-java</id>
            <goals>
                <goal>generate</goal>
            </goals>
            <configuration>
                <inputSpec>${basedir}/src/main/resources/swagger/cview.yaml</inputSpec>
                <apiPackage>client.api</apiPackage>
                <modelPackage>client.model</modelPackage>
                <output>${project.build.directory}/generated-sources</output>
                <language>java</language>
                <configOptions>
                    <dateLibrary>java8</dateLibrary>
                    <library>jersey2</library>
                </configOptions>
            </configuration>
        </execution>
    </executions>
</plugin>

与主类一起运行,效果很好

public static void main(final String[] args) {
 SpringApplication.run(SpringBootApp.class, args);
}

但是当我在 WebSphere libertyCore 上使用 SpringBootServletInitializer 运行它时,它会卡住并在我尝试调用 Web 服务时给我这些错误:

org.codehaus.jackson.map.exc.UnrecognizedPropertyException: Unrecognized field "id_entite" (Class client.model.GaEj), not marked as ignorable

Problem with reading the data, class client.model.SearchResultGaEj, ContentType: application/json;charset=UTF-8

问题是我对org.codehaus.jackson.*没有任何依赖

我只用com.fasterxml.jackson.datatype

【问题讨论】:

  • 确保在部署时使用 parent-first/system-last 类加载。
  • 我不明白!

标签: java spring-boot jackson websphere-liberty


【解决方案1】:

默认情况下,WebSphere 使用 Codehaus Jackson (reference)。 WebSphere 使用两个Class-loader modesParent firstParent last。您需要确保应用程序使用来自FasterXML 而不是来自CodehauseJacksonSpring Boot 没有任何自己的托管库,但 WebSphere 是一个 Application Server,它提供了许多已附加的库,因此您无需为您的应用提供它们。

见:

  1. Catch JsonProcessingException from Jackson in Websphere Liberty
  2. Change Default JSON Provider on WebSphere Application Server
  3. Override Jackson Object Mapper properties on Websphere 8.5.5 using Apache Wink
  4. How to change Jackson version in JAX-RS app (WebSphere Liberty)

【讨论】:

  • Ziober 问题是:我应该从我的 server.xml 中添加还是删除功能?因为在我的机器上工作正常,所以当我在 WebSphere 上部署时,问题就来了!
  • 在您的机器上,您不使用WebSphere,而是使用带有嵌入式Web 服务器的Spring BootTomcatJetty。在这两台服务器上,不会出现此问题。它出现在WebSphere 上,因为它包含的不仅仅是简单的HTTP 服务器。你读过我参考的文章吗?现在我无法准确指出您必须删除的内容,我希望您阅读这些文章并自己深入研究文档和配置。这或多或少是像WebSphereJBoss 这样的服务器的普遍问题,我们需要为此禁用内部库并更改路径顺序。
  • 看看这个page,它描述了如何配置ParentLastClassLoader
猜你喜欢
  • 2019-09-21
  • 2017-04-04
  • 1970-01-01
  • 1970-01-01
  • 2020-02-02
  • 2019-05-20
  • 1970-01-01
  • 1970-01-01
  • 2022-12-16
相关资源
最近更新 更多