apache / dubbo

The java implementation of Apache Dubbo. An RPC and microservice framework.
https://dubbo.apache.org/
Apache License 2.0
40.4k stars 26.42k forks source link

dubbo rest模块内置的swagger会改变spring boot默认行为 #6841

Closed klzami closed 2 years ago

klzami commented 3 years ago

Environment

Steps to reproduce this issue

  1. 基于spring boot 1.5.x搭建demo项目并编写测试controller

  2. 访问该测试controller,默认返回json格式的response

  3. 引用以下包:

        <dependency>
            <groupId>org.apache.dubbo</groupId>
            <artifactId>dubbo-spring-boot-starter</artifactId>
            <version>2.7.7</version>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>2.9.2</version>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>2.9.2</version>
        </dependency>
        <dependency>
            <groupId>io.swagger</groupId>
            <artifactId>swagger-jersey2-jaxrs</artifactId>
            <version>1.5.9</version>
        </dependency>
  4. 重启demo项目并再次访问测试controller,这时会返回xml格式的response

Expected Result

引用swagger不改变spring boot的默认http message converter组织方式,不影响各接口的response格式。

Actual Result

引用swagger后改变了spring boot的默认http message converter组织方式,进而改变了各接口的response格式。

Trouble Shooting

  1. dubbo rest集成了swagger,用到了相关的类,比如:io.swagger.jaxrs.listing.BaseApiListingResource
  2. 因此必须引用 swagger-jersey2-jaxrs 包。
  3. swagger-jersey2-jaxrs 包引用了 jackson-dataformat-xml包。
  4. jackson-dataformat-xml内部的 XmlMapper类会改变SpringBoot的HttpMessageConverter组装过程,从而改变默认response格式。
blindarcheology commented 3 years ago

can you provide a recurring case for this issue. Thanks!

CrazyHZM commented 2 years ago

I think this is not a problem that dubbo needs to solve. You can try to specify application/json in the header and specify the http message in json format.