Java Spring Session not persist between requests

后端 未结 2 1370
南方客
南方客 2021-01-26 10:56

I have this controller

@Controller
@RequestMapping(value = \"/login\")
public class Login{

    @RequestMapping
    public ModelAndView mainPage(HttpServletReque         


        
相关标签:
2条回答
  • 2021-01-26 11:24

    Are you using spring security? May be you can set http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.NEVER) if you are managing sessions by yourself

    Reference: https://www.baeldung.com/spring-security-session

    0 讨论(0)
  • 2021-01-26 11:28

    The real problem was at JSessionID path.

    The path of JSessionID was /myapp. That was result of Tomcat, because my app normaly run under mydom.com:8080/myapp

    But with Apache as reverse proxy, I run my app directly from mydom.com/, which make JSessionID invalid because I'm not on mydom.com/myapp.

    So I added a new line in virtual host from Apache(where is setted reverse proxy) to change the path of cookies:

    ProxyPassReverseCookiePath /myapp /
    

    This is my final VirtualHost and now Session persist between requests.

    <VirtualHost *:80>
    
        ServerName mydom.com
    
        ProxyRequests Off
        ProxyPreserveHost On
        ProxyPass / http://127.0.0.1:8080/myapp/
        ProxyPassReverse / http://127.0.0.1:8080/myapp/
        ProxyPassReverseCookiePath /myapp /
    
    </VirtualHost>
    
    0 讨论(0)
提交回复
热议问题