重定向反向代理后面的 spring 应用程序丢失 flash 属性 [英] Redirect a spring application behind reversy proxy lose flash attributes

查看:65
本文介绍了重定向反向代理后面的 spring 应用程序丢失 flash 属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序在 POST 操作后将一些信息重定向到 GET 控制器,但在与 Apache 和反向代理一起使用时会丢失这些信息.当我在中间没有反向代理的情况下执行此操作时,一切正常.一些想法?

My applications redirects after POST operation some information to the GET controller but lose the information when using with Apache and reverse proxy. When I do this operation without the reverse proxy in the middle everything works fine. Some ideas?

    @PreAuthorize("hasRole('ROLE_ADMIN')")
    @RequestMapping(value = "aCategory", method = RequestMethod.POST)
    public String category(@RequestParam("aCategoryName") String name, Model model, RedirectAttributes attr,
                        HttpServletRequest request) {

                String redirect = "redirect:" + "http://localhost:8080/aCategory";
                aService.saveACategory(name);
                attr.addFlashAttribute("aCategoryName", name);
                return redirect;
    }


    @RequestMapping(value = "aCategory", method = RequestMethod.GET, produces = "text/html")
    public String appCategory(Model model, Principal principal) {
        String name = principal.getName(); // get logged in username
        model.addAttribute("username", name);
        return "aCategory";
    }

推荐答案

这取决于您的集群配置和会话复制配置.因为 FlashAttributes 在将其添加到模型映射以在重定向视图上显示之前首先临时存储在会话中.因此,如果您的集群没有为正确的会话复制进行良好配置,那么当请求由另一个集群提供服务时,您的 FlashAttribute 可能会丢失,而不是 FlashAttribute 实际存储在会话中的位置.

It depends on your cluster configuration and session replication configuration. Because FlashAttributes are first stored in a session temporarily before adding it to the model map to display it on the redirected view. So if your cluster is not well configured for proper session replication then your FlashAttribute might be lost when request is served by another cluster than where the FlashAttribute is actually stored in session.

有关更多详细信息,您可以参考我的问题.

For further details you can refer my question.

希望对你有帮助.干杯.

Hope this helps you. Cheers.

这篇关于重定向反向代理后面的 spring 应用程序丢失 flash 属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆