Spring Cloud 整合 Swagger2 3.0.0 修改 baseURL

环境

  • Spring Cloud Alibaba
  • Nacos
  • Swagger2 3.3.0
  • System 服务

方法

修改 System 服务的 bootstrap.properties,添加以下内容

# swagger2
springfox.documentation.swagger.v2.path=/system/v2/api-docs

# swagger3
springfox.documentation.open-api.v3.path=/system/v3/api-docs

说明

Swagger2

查看源码

包名: io.springfox:springfox-swagger2:3.0.0

类名:springfox.documentation.swagger2.web.Swagger2ControllerWebMvc

@ApiIgnore
@RestController
@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.SERVLET)
@RequestMapping(SWAGGER2_SPECIFICATION_PATH)
@Conditional(OnServletBasedWebApplication.class)
@Order(Ordered.HIGHEST_PRECEDENCE)
public class Swagger2ControllerWebMvc {
    public static final String SWAGGER2_SPECIFICATION_PATH
      = "${springfox.documentation.swagger.v2.path:/v2/api-docs}";
    ...
}

@RequestMapping 注解的值为:SWAGGER2_SPECIFICATION_PATH,该变量会读取 springfox.documentation.swagger.v2.path 配置的值,缺省值为:/v2/api-docs

Swagger3

查看源码

包名:io.springfox:springfox-oas:3.0.0

类名:springfox.documentation.oas.web.OpenApiControllerWebMvc

@ApiIgnore
@RestController
@RequestMapping(OPEN_API_SPECIFICATION_PATH)
@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.SERVLET)
@Conditional(OnServletBasedWebApplication.class)
public class OpenApiControllerWebMvc {
    ...
}

@RequestMapping 注解的值为:OPEN_API_SPECIFICATION_PATH,该变量会读取 springfox.documentation.open-api.v3.path 配置的值,缺省值为:/v3/api-docs

package springfox.documentation.oas.web;
...
public class SpecGeneration {
    private static final Logger LOGGER = getLogger(SpecGeneration.class);
    public static final String OPEN_API_SPECIFICATION_PATH
        = "${springfox.documentation.open-api.v3.path:/v3/api-docs}";
    protected static final String HAL_MEDIA_TYPE = "application/hal+json";
    ...
}

你可能感兴趣的:(Web,spring,cloud,alibaba,swagger2,swagger3)