Spring mvc ServletUriComponentsBuilder.fromRequest返回http方案而不是https
我有一个由前端代码组成的web应用程序,它调用由两个后端模块实现的相同api。此api返回JSON对象中的url。后端模块都是用SpringMVC编写的,但版本不同。 url构建是相同的,如下所示:Spring mvc ServletUriComponentsBuilder.fromRequest返回http方案而不是https,spring-mvc,Spring Mvc,我有一个由前端代码组成的web应用程序,它调用由两个后端模块实现的相同api。此api返回JSON对象中的url。后端模块都是用SpringMVC编写的,但版本不同。 url构建是相同的,如下所示: @GetMapping(path = "/app1/menu", produces = MediaType.APPLICATION_JSON_UTF8_VALUE) public JsonObject getMenu(HttpServletRequest req) throws IOExcep
@GetMapping(path = "/app1/menu", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public JsonObject getMenu(HttpServletRequest req) throws IOException {
JsonObject menu = new JsonObject();
menu.addProperty("href", ServletUriComponentsBuilder.fromRequest(req)
.replacePath(req.getContextPath())
.path("/index.html")
.toUriString());
return menu;
}
https://example.com/context/app1/menu
正如您所看到的,这段代码只是向传入的请求添加一个常量并返回它。
第一个应用程序使用SpringMVC4(4.3.5.0版本)。
第二个模块使用5.1.4.0版本。
当所有这些应用程序都部署在负载平衡服务器(2个tomcat实例,前面有一个负载平衡器)和https上时,问题就出现了。
假设app1的请求url如下所示:
@GetMapping(path = "/app1/menu", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public JsonObject getMenu(HttpServletRequest req) throws IOException {
JsonObject menu = new JsonObject();
menu.addProperty("href", ServletUriComponentsBuilder.fromRequest(req)
.replacePath(req.getContextPath())
.path("/index.html")
.toUriString());
return menu;
}
https://example.com/context/app1/menu
app1正确返回
https://example.com/context/index.html
对于app2,前端发出的请求是
答案是
因此,它放松了https方案
ServletUriComponentsBuilder.fromRequest似乎已更改行为?
我(很快地承认)看过git回购协议中的承诺,但还没有
发现了什么