【发布时间】:2020-07-24 19:54:11
【问题描述】:
我正在尝试在我的 Spring Boot 应用程序中添加 Swagger UI,但我无法访问 swagger-ui.html。
pom.xml
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.1.RELEASE</version>
</parent>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-elasticsearch</artifactId>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-spring-webflux</artifactId>
<version>3.0.0</version>
</dependency>
代码:
@Configuration
public class SwaggerConfig {
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2).select()
.apis(RequestHandlerSelectors.basePackage("com.learnings.search.web")).build().pathMapping("/")
.enableUrlTemplating(false);
}
}
@SpringBootApplication(exclude = { DataSourceAutoConfiguration.class, CassandraAutoConfiguration.class,
KafkaAutoConfiguration.class })
@EnableSwagger2
public class SearchApp {
public static void main(String[] args) {
SpringApplication.run(SearchApp.class, args);
}
}
我能够访问 swagger 资源:
/swagger-resources
[
{
"name": "default",
"url": "/v2/api-docs",
"swaggerVersion": "2.0",
"location": "/v2/api-docs"
}
]
/swagger-resources/configuration/ui
{
"deepLinking": true,
"displayOperationId": false,
"defaultModelsExpandDepth": 1,
"defaultModelExpandDepth": 1,
"defaultModelRendering": "example",
"displayRequestDuration": false,
"docExpansion": "none",
"filter": false,
"operationsSorter": "alpha",
"showExtensions": false,
"showCommonExtensions": false,
"tagsSorter": "alpha",
"validatorUrl": "",
"supportedSubmitMethods": [
"get",
"put",
"post",
"delete",
"options",
"head",
"patch",
"trace"
],
"swaggerBaseUiUrl": ""
}
如果最新版本有什么变化,请告诉我,因为我在其他项目中一直在使用 swagger-ui。
【问题讨论】:
-
我面临同样的错误。你解决了吗?
标签: spring spring-boot swagger-ui