我们已经通过在application.properties中使用"/api"
在api中将基本路径配置为具有server.servlet-path=/api
,现在在http://host:port/api/swagger-ui.html
中可以使用swagger文档
但是,由于我们所有的服务文档都可以在http://host:8080/swagger-ui.html
上获得,因此我们希望该服务也以相同的路径提供。
现在,我想拦截对http://host:8080/swagger-ui.html
的api调用并将其重定向到http://host:8080/api/swagger-ui.html
。
@RestController
@RequestMapping(path = "/")
public class SwaggerRedirectController {
@GetMapping(value = "/swagger-ui.html")
public void redirectToTwitter(HttpServletResponse httpServletResponse) throws IOException {
httpServletResponse.sendRedirect("https://host/api/swagger-ui.html");
由于我们已经将基本路径设置为“ / api”,所以尽管请求将发送到/swagger-ui.html,但它会附加“ / api”作为基本路径,并且不会点击此自定义api。
我想拦截此请求并从其中删除"/api"
,以便它将命中此自定义api,最终将其重定向到/api/swagger-ui.html
这可能吗?或其他任何方式