Java Swagger ui返回白标签错误

Java Swagger ui返回白标签错误,java,swagger,swagger-ui,Java,Swagger,Swagger Ui,我在spring boot应用程序中使用了swagger 2.9.2 localhost:8080/api文档工作正常 但是,localhost:8080/swagger ui.html返回writelabel错误 localhost:8080/v2/swagger ui.html和localhost:8080/api/swagger ui.html返回相同的错误。 我一定错过了一些简单的事情。谢谢 Whitelabel Error Page This application has no ex

我在spring boot应用程序中使用了swagger 2.9.2

localhost:8080/api文档
工作正常

但是,
localhost:8080/swagger ui.html
返回
writelabel错误

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

编译(“io.springfox:springfox-swagger2:2.9.2”)

compile(“io.springfox:springfox-swagger-ui:2.9.2”)


返回Docket bean,如下所示:

@Bean
public Docket api() {
    return new Docket(DocumentationType.SWAGGER_2)
            .select()
            .apis(RequestHandlerSelectors.any())
            .paths(PathSelectors.any())
            .build()
            .apiInfo(apiInfo());
}

并在控制器类上方添加
@RestController
注释

嘿,我使用的是Spring boot 2.1.4和Swagger 2.9.2,我遇到了同样的问题,并通过以下方式得到了解决:

  • 似乎您具有所需的依赖项,因此这不是问题所在
  • 我认为您必须实现WebMvcConfigure并覆盖addResourceHandlers方法的问题:

    @Configuration
    @EnableSwagger2
    public class SwaggerConfig implements WebMvcConfigurer {
     // your Docket and ApiInfo methods
    
     @Override
     public void addResourceHandlers(ResourceHandlerRegistry registry) {
     registry.addResourceHandler("swagger-ui.html")
            .addResourceLocations("classpath:/META-INF/resources/");
     registry.addResourceHandler("/webjars/**")
            .addResourceLocations("classpath:/META-INF/resources/webjars/");
     }
    
试着添加它,并与你分享发生的事情

因此,如果您正确编写了swaggerConfig,那么代码还添加了正确的依赖项,并且仍然会出错
So if u have correctly written the swaggerConfig code also added the right dependencies and still getting error
The ultimate solution is 
You need to have perfect combination of swagger version and spring boot version

Just change the spring boot and swagger version as below
Check in your pom.xml or gradle build
Spring boot version :- <version>1.4.1.RELEASE</version>
Swagger and Sawgger ur version:- <version>2.2.2</version>

There are other combinations available but that u need to try on trial basis
最终的解决办法是 你需要有一个完美的组合,大摇大摆的版本和弹簧启动版本 只需按如下所示更改spring boot和swagger版本 签入pom.xml或gradle构建 Spring启动版本:-1.4.1.0版本 斯威格和萨威格ur版本:-2.2.2 有其他组合可用,但你需要尝试的基础上
我也有同样的问题,用这个Docket bean配置解决:

@Bean
public Docket api() {
    return new Docket(DocumentationType.SWAGGER_2)
            .select()
            .apis(RequestHandlerSelectors.any())
            .paths(Predicates.not(PathSelectors.regex("/error.*")))
            .build()
            .apiInfo(this.apiInfo());
}

它对我很有用。

你能试试
路径选择器.any()
而不是
路径选择器.ant(“/api/**”)
看看它是否改变了什么吗?@Arnaud试过了,不起作用。相同的error@toosensitive您找到解决方案了吗?@toosensitive能否请您共享代码的GitHub链接,以便我检查?
@Bean
public Docket api() {
    return new Docket(DocumentationType.SWAGGER_2)
            .select()
            .apis(RequestHandlerSelectors.any())
            .paths(Predicates.not(PathSelectors.regex("/error.*")))
            .build()
            .apiInfo(this.apiInfo());
}