簡體   English   中英

Springfox - 改變 swagger-ui 的路徑

[英]Springfox - change path of swagger-ui

現在 swagger 來自http://localhost:8080/myContextRoot/swagger-ui.html

我可以將 swagger 及其資源配置為在http://localhost:8080/myContextRoot/swagger/swagger-ui.html 下提供服務嗎

感謝您的幫助!

我遵循了這種方法:

依賴:

implementation 'org.tuckey:urlrewritefilter:4.0.4'

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);
    }
  }
}

並在資源文件夾 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>

之后,招搖的路徑是:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM