Springdoc:打开swagger-ui.html时得到404

时间:2020-06-16 20:14:49

标签: spring-boot swagger-ui springdoc springdoc-openapi-ui

我安装了最新的Spring Boot应用程序和springdoc.swagger-ui。

<dependency>
    <groupId>io.swagger</groupId>
    <artifactId>swagger-annotations</artifactId>
    <version>1.6.1</version>
</dependency>
<dependency>
    <groupId>org.springdoc</groupId>
    <artifactId>springdoc-openapi-ui</artifactId>
    <version>1.2.32</version>
</dependency>

我的application.properties包含springdoc.swagger-ui.path = / swagger-ui-openapi.html

当我通过Intellij IDEA运行应用程序时,http://localhost:8080/swagger-ui-openapi.html带我到http://localhost:8080/swagger-ui/index.html?configUrl=/v3/api-docs/swagger-config 和Swagger UI页面加载成功。

但是,如果我通过以下命令行启动应用程序:“ java -jar my-app.jar”,则在尝试访问http://localhost:8080/swagger-ui-openapi.html时,浏览器中出现404错误,日志“ Circular view path [error]”中出现错误 然后将我重定向到http://localhost:8080/swagger-ui/index.html?configUrl=/v3/api-docs/swagger-config

javax.servlet.ServletException: Circular view path [error]: would dispatch back to the current handler URL [/error] again. Check your ViewResolver setup! (Hint: This may be the result of an unspecified view, due to default view name generation.)

但是http://localhost:8080/v3/api-docs可以访问,并且该地址有可用的模式。

我该如何解决?

1 个答案:

答案 0 :(得分:0)

springdoc-openapi不需要swagger-annotations v1.6.1依赖性;

默认情况下,使用springdoc,不需要任何ViewResolver的附加设置。

您可以看一些示例代码: