简体   繁体   English

Springfox - 改变 swagger-ui 的路径

[英]Springfox - change path of swagger-ui

now swagger is served from http://localhost:8080/myContextRoot/swagger-ui.html现在 swagger 来自http://localhost:8080/myContextRoot/swagger-ui.html

Can I configure swagger and its resources to be served under http://localhost:8080/myContextRoot/swagger/swagger-ui.html我可以将 swagger 及其资源配置为在http://localhost:8080/myContextRoot/swagger/swagger-ui.html 下提供服务吗

thank you for your help!感谢您的帮助!

I've followed this approach:我遵循了这种方法:

Dependency:依赖:

implementation 'org.tuckey:urlrewritefilter:4.0.4'

UrlRewrite Class: UrlRewrite 类:

@Component
public class SwaggerUrlRewriteFilter extends UrlRewriteFilter {
  private static final String CONFIG_LOCATION = "/urlrewrite.xml";

  @Value("classpath:/urlrewrite.xml")
  private Resource resource;

  @Override
  protected void loadUrlRewriter(FilterConfig filterConfig) throws ServletException {
    try {
      //Create a UrlRewrite Conf object with the injected resource
      Conf conf = new Conf(filterConfig.getServletContext(), resource.getInputStream(), resource.getFilename(), "@@yourOwnSystemId@@");
      checkConf(conf);
    } catch (IOException ex) {
      throw new ServletException("Unable to load URL rewrite configuration file from " + CONFIG_LOCATION, ex);
    }
  }
}

and in the resource folder urlrewrite.xml并在资源文件夹 urlrewrite.xml 中

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE urlrewrite PUBLIC "-//tuckey.org//DTD UrlRewrite 4.0//EN"
        "http://www.tuckey.org/res/dtds/urlrewrite4.0.dtd">
<urlrewrite>
    <rule>
        <from>/swagger/swagger-ui.html</from>
        <to type="passthrough">/swagger-ui.html</to>
    </rule>

    <rule>
        <from>/swagger/webjars/(.*)</from>
        <to type="passthrough">/webjars/$1</to>
    </rule>

    <rule>
        <from>/swagger/v2/api-docs</from>
        <to type="passthrough">/v2/api-docs</to>
    </rule>

    <rule>
        <from>/swagger/configuration/(.*)</from>
        <to type="passthrough">/configuration/$1</to>
    </rule>

    <rule>
        <from>/swagger/swagger-resources</from>
        <to type="passthrough">/swagger-resources</to>
    </rule>
</urlrewrite>

after that the path to swagger is:之后,招摇的路径是:

http://localhost:8080/myContextRoot/swagger/swagger-ui.html http://localhost:8080/myContextRoot/swagger/swagger-ui.html

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Springfox swagger-ui 不使用内容类型 header 发送 - Springfox swagger-ui not sending with content-type header 如何使用 swagger-ui(springfox-swagger2 和 springfox-swagger-ui)和 spring-boot 应用程序上传多个文件? - How to upload multiple files using swagger-ui (springfox-swagger2 and springfox-swagger-ui) and spring-boot application? 是否可以在与主应用程序不同的端口上运行 SpringFox 的 swagger 和 swagger-ui? - Is it possible to run SpringFox' swagger and swagger-ui on a different port than the main application? 如何更改 Swagger-ui URL 前缀? - How to change Swagger-ui URL prefix? Springfox Swagger-UI - 隐藏或过滤不使用其他模型的不同请求的字段 - Springfox Swagger-UI - hide or filter fields for different requests not using additional models Springfox:拒绝/防止在swagger-ui中使用RestController主体中的子类作为模型 - Springfox: deny/prevent to use subclass as model from RestController body in swagger-ui 无法使用 Springfox 2.9.2 从 Swagger-UI 发送授权令牌 - Cannot send Authorization token from Swagger-UI using Springfox 2.9.2 添加了 Springfox Swagger-UI 但它不起作用,我错过了什么? - Added Springfox Swagger-UI and it's not working, what am I missing? Swagger-UI在根端点上不显示SpringBoot和path参数 - Swagger-UI Does not display with SpringBoot and path parameter on root endpoint 是否有任何选项可以为 /swagger-ui 路径添加前缀? 开放API - Is there any option to add a prefix for /swagger-ui path? OpenApi
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM