我正在尝试将 swagger-ui (OpenAPI 3.0) 添加到 Spring Boot v3 应用程序中。
我已经添加了 openapi-ui maven 依赖项,它应该按照文档工作。
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>1.6.11</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
但显然,它仍然不起作用,并且 localhost:8080/swagger-ui.html 返回 404 错误。
我缺少什么?
按照此处的说明操作:
http://www.baeldung.com/swagger-2-documentation-for-spring-rest-api
我将这些依赖项添加到我的项目中:
compile "io.springfox:springfox-swagger2:2.7.0"
compile "io.springfox:springfox-swagger-ui:2.7.0"
Run Code Online (Sandbox Code Playgroud)
并像这样配置 SpringFox Swagger:
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any())
.build();
}
}
Run Code Online (Sandbox Code Playgroud)
但是 Swagger UI 似乎没有启用。我试过:
我得到的只是:
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Mon Sep 11 09:43:46 BST 2017
There was an …Run Code Online (Sandbox Code Playgroud)