【发布时间】:2018-08-22 15:08:40
【问题描述】:
我在我的 Spring Boot 应用中使用了 swagger 2.9.2。
localhost:8080/api-docs 工作正常。
但是,localhost:8080/swagger-ui.html 返回writelabel error。
localhost:8080/v2/swagger-ui.html 和 localhost:8080/api/swagger-ui.html 返回相同的错误。
我一定错过了一些简单的事情。谢谢。
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Wed Aug 22 10:05:48 CDT 2018
There was an unexpected error (type=Not Found, status=404).
No message available
在build.gradle,我有springfox的依赖。
compile("io.springfox:springfox-swagger2:2.9.2")compile("io.springfox:springfox-swagger-ui:2.9.2")
swaggerconfig.java
@Configuration
@EnableSwagger2
public class SwaggerConfig{
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.basePackage(MyServiceController.class.getPackage().getName()))
//.apis(RequestHandlerSelectors.withClassAnnotation(Api.class))
.paths(PathSelectors.ant("/api/**"))
.build()
.apiInfo(apiInfo());
}
private ApiInfo apiInfo() {
String description = "Company - My API";
return new ApiInfoBuilder()
.title("REST API")
.description(description)
.version("1.0")
.build();
}
MyServiceController.java
@ApiOperation(value = "some description",
response = MyServiceResponse.class)
@ApiResponses(value = {
@ApiResponse(code = 200, message = "ok"),
@ApiResponse(code = 400, message = "Bad Request"),
@ApiResponse(code = 401, message = "not authorized"),
@ApiResponse(code = 403, message = "not authenticated"),
@ApiResponse(code = 404, message = "The resource you were trying to reach is not found"),
@ApiResponse(code=500, message = "Interval Server Error")
})
@RequestMapping(method = RequestMethod.POST, value = "/api/component/operation", consumes = APPLICATION_JSON_VALUE, produces = APPLICATION_JSON_VALUE)
@ResponseBody
{
do something
}
【问题讨论】:
-
你能试试
PathSelectors.any()而不是PathSelectors.ant("/api/**")看看它是否改变了什么? -
@Arnaud 试过了,没用。同样的错误
-
@toosensitive 你找到解决方案了吗?
标签: java swagger swagger-ui