Spring boot 尝试使用springfox配置访问swagger-ui.html时出现白标签错误页面

Spring boot 尝试使用springfox配置访问swagger-ui.html时出现白标签错误页面,spring-boot,swagger,springfox,Spring Boot,Swagger,Springfox,我正在尝试使用Springfox和以下文档从springboot项目生成Swagger文档 最初,由于我在应用程序中使用OAuth2,所以出现错误“访问资源需要完全授权”。我更改了配置以允许所有以/swagger-ui.html结尾的请求 现在,当我试图在本地计算机上访问/swagger-ui.html时,我得到了“WhiteLabel错误页面-此应用程序没有/error的显式映射” 我浏览了很多帖子,但是没有一个解决方案对我有效——我没有使用@webmvcconfiguration,因为它会干

我正在尝试使用Springfox和以下文档从springboot项目生成Swagger文档

最初,由于我在应用程序中使用OAuth2,所以出现错误“访问资源需要完全授权”。我更改了配置以允许所有以/swagger-ui.html结尾的请求

现在,当我试图在本地计算机上访问/swagger-ui.html时,我得到了“WhiteLabel错误页面-此应用程序没有/error的显式映射”

我浏览了很多帖子,但是没有一个解决方案对我有效——我没有使用@webmvcconfiguration,因为它会干扰我。
有人能帮忙吗?

swagger-ui.html页面会多次调用以获取所有详细信息。如果您使用浏览器的开发工具(通常只需按F12键打开),您将在“网络”选项卡中看到失败的请求。您需要允许请求

    "/v2/api-docs",
    "/swagger-resources/**",
    "/swagger-ui.html**",
    "/webjars/**"

中有一些信息,查找“安全”或“授权”

swagger-ui.html页面会多次调用以获取所有详细信息。如果您使用浏览器的开发工具(通常只需按F12键打开),您将在“网络”选项卡中看到失败的请求。您需要允许请求

    "/v2/api-docs",
    "/swagger-resources/**",
    "/swagger-ui.html**",
    "/webjars/**"

中有一些信息,请查找“安全”或“授权”

对于Swagger 3.0,URL更改为


对于Swagger 3.0,URL更改为

  • 从pom.xml中删除v2依赖项或将其注释掉

     <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>
    
    
    伊奥·斯普林福克斯
    

  • 从pom.xml中删除v2依赖项或将其注释掉

     <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>
    
    
    伊奥·斯普林福克斯
    
    这就是我解决问题的方法。这是我的详细代码,如果有人想看的话

    现在,我使用了3.0.0-SNAPSHOT和我在此创建的最新spring boot starter项目:

  • 在My pom.xml中,我添加了以下依赖项:
  • 在我的SpringBoot Main/Runner类中,我添加了这些注释
  • 我的摘要返回函数如下所示
  • 最后,我从
  • http://localhost:8080/swagger-ui/index.html#


    这就是我解决问题的方法。这是我的详细代码,如果有人想看的话

    现在,我使用了3.0.0-SNAPSHOT和我在此创建的最新spring boot starter项目:

  • 在My pom.xml中,我添加了以下依赖项:
  • 在我的SpringBoot Main/Runner类中,我添加了这些注释
  • 我的摘要返回函数如下所示
  • 最后,我从
  • http://localhost:8080/swagger-ui/index.html#


    谢谢!我还认为这是一些安全问题。但这是一个url问题。我试图使用localhost:8080//swagger-ui.html点击swagger-ui.html,但是它在localhost:8080/swagger-ui.html上工作。如何允许这些请求???我在哪里写这些行?在月食中?哪个文件?应用程序。属性???请尝试禁用所有安全检查,谢谢!我还认为这是一些安全问题。但这是一个url问题。我试图使用localhost:8080//swagger-ui.html点击swagger-ui.html,但是它在localhost:8080/swagger-ui.html上工作。如何允许这些请求???我在哪里写这些行?在月食中?哪个文件?application.properties???尝试禁用所有安全检查,
    spring.resources.add-mappings=true
    
    @EnableWebMvc
    @EnableSwagger2
    @SpringBootApplication
    
    @Bean
        public Docket productApi() {
            Contact contact =new Contact(
                    "Vineet Mishra",
                    "https://github.com/xbox2204",
                    "whatwillyoudo@withmyemail.com"
            );
            ApiInfo apiInfo= new ApiInfoBuilder().title("VINEET SPRING-BOOT API")
                    .description("Spring-Boot for all")
                    .termsOfServiceUrl("jUST CHILL!!!")
                    .contact(contact)
                    .licenseUrl("something@something.com").version("1.0").build();
    
            return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo)
                    .select()
                    .apis(RequestHandlerSelectors.any())
                    .build();
        }