【问题标题】:Accessing Swagger outside the Spring Boot Context path在 Spring Boot Context 路径之外访问 Swagger
【发布时间】:2018-09-17 07:44:05
【问题描述】:

我的 Spring Boot 应用程序有一个如下所示的 contextPath

server.contextPath=/api

我已经添加了 springfox swagger 配置,并且能够从给定的 url 中获取 swagger url,如下所示

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

实际上我想要的是在 contextPath 之外获得 swagger ui,如下所示

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

想知道这是否可行。

【问题讨论】:

  • 然后从属性文件中删除 server.contextPath=/api
  • 感谢您的回复....我无法删除我的应用程序的 contextPath...任何其他方式而不是删除 contextPath
  • 那你为什么要拥有任何上下文路径的应用程序?
  • Spring Boot 应用程序已经有使用此上下文路径的 api...并且客户端要求不要为 swagger ui 使用应用程序上下文路径
  • 您的问题不清楚,您是说,您将使用 swagger 而不使用上下文路径,但您不会删除上下文路径。那你觉得怎么做呢?

标签: java spring-boot swagger-ui swagger-2.0 springfox


【解决方案1】:

我没有尝试过,但也许它可以帮助你。如果这是找出 swagger 是否正在运行的方法,如果是,您可以动态设置

 System.setProperty("server.servlet.context-path", "/");
SpringApplication.run(Application.class, args);

但正如我所说,我没有测试,也许这很愚蠢。无论如何,我会尝试测试一些解决方案,然后我会写信给你

【讨论】:

  • 这又是在删除应用程序 contextPath
  • 我的意思是不同的。稍后我会尝试并写信给你:)。
猜你喜欢
  • 2018-09-20
  • 2018-01-27
  • 2021-03-12
  • 2019-04-26
  • 2018-09-23
  • 1970-01-01
  • 2021-12-31
相关资源
最近更新 更多