【发布时间】:2019-08-21 04:07:38
【问题描述】:
我需要以下物品:
任何请求
- https://localhost:8443
- https://localhost:8443/
- https://localhost:8443/test
- https://localhost:8443/api
等等,应该转发给
https://localhost:8443/a/web/index.html
现在,我就是这样做的:
@Controller
public class ForwardController {
@RequestMapping(value = "/*", method = RequestMethod.GET)
public String redirectRoot(HttpServletRequest request) {
return "forward:/a/web/index.html";
}
}
问题是:
这也匹配 https://localhost:8443/api/(注意末尾的 /)。
这是一个问题,因为这是我希望 Spring Data REST 基本路径所在的位置:
spring.data.rest.base-path=/api/
/api != /api/涉及 REST 端点。
什么应该有效,但不知何故没有
我尝试了几种不同的正则表达式,但仍然无法完成我想要的。例如(demo):
@RequestMapping(value = "/[^/]+", method = RequestMethod.GET)
现在将适用于 Spring Data - 我获得了我期望的所有资源信息,但访问 https://localhost:8443/ 现在已损坏,无法再访问 Web 客户端。
同样的道理
@RequestMapping(value = "/{path}", method = RequestMethod.GET)
@RequestMapping(value = "/{path:[^/]+}", method = RequestMethod.GET)
其行为类似于/*(也匹配下一个/)。
这个问题已经困扰了我好几个星期,但仍然没有解决方案的见解。
整个问题也可以看成:
为什么"/[^/]+" 不匹配https://localhost:8443/whatever?
【问题讨论】:
-
@NestorSokil 嗯,我不认为这个答案可以帮助我。只是添加一个匹配所有不匹配的端点在这里没有帮助 - 这实际上是问题。
标签: regex spring spring-boot spring-data-jpa