我正在使用以下 Maven 依赖项和插件
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.0.3-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-spring-web</artifactId>
<version>2.0.3-SNAPSHOT</version>
</dependency>
<repository>
<id>jcenter-snapshots</id>
<name>jcenter</name>
<!-- <url>https://jcenter.bintray.com/</url> -->
<url>http://oss.jfrog.org/artifactory/oss-snapshot-local/</url>
</repository>
下面的beans.xml中是bean的定义如下:
<int:annotation-config/>
<context:annotation-config/>
<bean id="swagger2Config" class="springfox.documentation.swagger2.configuration.Swagger2DocumentationConfiguration"/>
<bean id="springConfig" class="com.example.SpringConfig"/>
我引用了以下blog
我无法使用博客中提到的早期访问版本,因为它无法下载。我已将版本更改为 2.0.3-SNAPSHOT,现在我看到 HttpMediaTypeNotAcceptableException 异常。我能够生成 WAR 文件,并且当我尝试使用 http://localhost:8080/example/v2/api-docs 访问它时,我能够在日志中看到使用 Swagger 正确创建的资源组。抛出了上述异常。
请帮忙。
最佳答案
首先,看起来依赖项在 Maven Central 上再次可用。自从我写那个博客以来,这是一个进步。 至少有 2.0.1 和 2.0.2 可用,因此如果您不想使用 JCentral,则无需再使用。
关于 HttpMediaTypeNotAcceptableException。在我的实验过程中我没有看到导致写这篇博客的原因,所以我无法给你一个明确的答案。
在阅读您的问题时,我确实注意到了一些相关问题:
这些表明可能缺少一些与 Jackson 2 相关的通用 Spring MVC 配置,或者 @ResponseBody 的翻译可能会对特定方法进行一些调整。检查这些问题,看看哪一个更适合您的情况。
关于java - Swagger 2.0.3 与 Spring MVC 抛出 HttpMediaTypeNotAcceptableException : Could not find acceptable representation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30917831/