首页

解决配置springfox-swagger访问swagger-ui.html浏览器弹出"Unable to infer base url. This is common when using dynamic servlet registration or when the API.."提示窗口

标签:springfox,swagger2,swagger-ui.html,swagger配置报错,EnableSwagger2     发布时间:2022-04-08   

一、问题描述

关于spring cloud项目配置io.springfoxswagger依赖(具体依赖如下gradle或pom配置),访问 http://localhost:9990/eureka-services/swagger-ui.html地址,如下图提示“Unable to infer base url. This is common when using dynamic servlet registration or when the API is behind an API Gateway. The base url is the root of where all the swagger resources are served. For e.g. if the api is available at http://example.org/api/v2/api-docs then the base url is http://example.org/api/. Please enter the location manually: ”窗口提示报错。

解决配置springfox-swagger访问swagger-ui.html浏览器弹出"Unable to infer base url. This is common when using dynamic servlet registration or when the API.."提示窗口

gradle依赖配置如下,更多配置版本下载

compile('io.springfox:springfox-swagger2:2.9.2')@b@compile('io.springfox:springfox-swagger-ui:2.9.2')

maven依赖配置,更多配置版本下载

<dependency>@b@    <groupId>io.springfox</groupId>@b@    <artifactId>springfox-swagger2</artifactId>@b@    <version>2.9.2</version>@b@</dependency>@b@<dependency>@b@    <groupId>io.springfox</groupId>@b@    <artifactId>springfox-swagger-ui</artifactId>@b@    <version>2.9.2</version>@b@</dependency>

二、解决方法

1、在项目的@SpringBootApplication启动类上加上@EnableSwagger2配置,即可解决问题(完整项目swagger-demo配置点击下载)

package com.xwood.cloud.eureka.services;@b@@b@import lombok.extern.slf4j.Slf4j;@b@import org.springframework.boot.SpringApplication;@b@import org.springframework.boot.autoconfigure.SpringBootApplication;@b@import org.springframework.cloud.client.loadbalancer.LoadBalanced;@b@import org.springframework.cloud.netflix.eureka.EnableEurekaClient; @b@import springfox.documentation.swagger2.annotations.EnableSwagger2;@b@@b@@SpringBootApplication@b@@EnableEurekaClient@b@@EnableSwagger2@b@@Slf4j@b@public class EurekaServicesApplication {@b@@b@   public static void main(String[] args) {@b@      try {@b@         SpringApplication.run(EurekaServicesApplication.class, args);@b@         log.info("EurekaServices  deploy  success ^_^.");@b@      } catch (Exception e) {@b@         e.printStackTrace();@b@         log.error("启动报错,error={}",e.getMessage(),e);@b@      }@b@   }@b@@b@@b@}

2、访问http://localhost:9990/eureka-services/swagger-ui.html效果如下图

解决配置springfox-swagger访问swagger-ui.html浏览器弹出 Unable to infer base url. This is common when using dynamic servlet registration or when the API.

  • <<相关内容>>
<<热门下载>>